How to keep UISearchBar placeholder left-aligned

I find that the iOS system (7.0+) keeps the alignment placeholder centered on the UISearchBar, but left-aligned in version 6.0. I want the UISearchBar placeholder to be left-aligned in all versions of iOS. then how can i handle this?

I am trying to add a space character in a UISearchBar placeHolder. It seems to solve the problem. But I want to know if there is an elegant method to solve this problem. Can God teach me to stop the problem?

+6
source share
1 answer
for (UIView *subView in self.subviews){ if ([subView isKindOfClass:[UITextField class]]) { UITextField *text = (UITextField*)subView; text.textAlignment = UITextAlignmentLeft; text.rightViewMode = UITextFieldViewModeAlways; } } 
0
source

Source: https://habr.com/ru/post/971642/


All Articles