右对齐UISearchbar占位符

tom*_*n11 1 iphone objective-c uisearchbar ios ios10

该代码曾经可以工作,但是在ios 10之后,它已停止运行:

UITextField *searchTextField = [_searchBar valueForKey:@"_searchField"];
searchTextField.textAlignment = NSTextAlignmentRight
Run Code Online (Sandbox Code Playgroud)

我已经尝试了段落和attributedPlaceholder,但占位符始终保持对齐。该错误出现在xcode 7和8中。如何解决此问题?

Abd*_*ekh 5

Maybe this a long time, here is the solution

Swift

searchBar.semanticContentAttribute = .forceRightToLeft
Run Code Online (Sandbox Code Playgroud)