1

This code used to work, but after ios 10 it has stopped functioning:

UITextField *searchTextField = [_searchBar valueForKey:@"_searchField"];
searchTextField.textAlignment = NSTextAlignmentRight

I have tried both paragraph and attributedPlaceholder, but the placeholder is always left aligned. The bug appears in xcode 7 and 8. How can I resolve this?

kb920
  • 2,979
  • 2
  • 31
  • 41
tomeron11
  • 374
  • 3
  • 14

2 Answers2

6

Maybe this a long time, here is the solution

Swift

searchBar.semanticContentAttribute = .forceRightToLeft
1

Don't use a UISearchBar if you need to do these kinds of customizations. You'll have to make your own using a UITextField and a UIImageView, and responding to the delegate calls.

Ravi B
  • 1,562
  • 2
  • 13
  • 30