简体   繁体   中英

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?

Maybe this a long time, here is the solution

Swift

searchBar.semanticContentAttribute = .forceRightToLeft

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM