Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right Align UISearchbar placeholder

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?

like image 827
tomeron11 Avatar asked May 09 '26 09:05

tomeron11


1 Answers

Maybe this a long time, here is the solution

Swift

searchBar.semanticContentAttribute = .forceRightToLeft
like image 96
Abdulaziz.Musaileekh Avatar answered May 10 '26 23:05

Abdulaziz.Musaileekh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!