本文介绍了是否可以更改UISearchBar占位符的对齐方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于输入语言不同,我需要在不同的路线上显示UISearchBar。
我看到,但我找不到你实际上将文本对齐到哪里a UISearchBar
。
I am going to need to show the UISearchBar in different alignments because of different input languages.
I saw this answer, but I can't find where is it that you actually align the text to the right on a UISearchBar
.
任何想法?
谢谢!
Any ideas?
Thanks!
推荐答案
这就是我所做的:
for (UIView *subView in self.subviews){
if ([subView isKindOfClass:[UITextField class]]) {
UITextField *text = (UITextField*)subView;
text.textAlignment = UITextAlignmentRight;
text.rightViewMode = UITextFieldViewModeAlways;
}
}
如果您还想移动放大镜图标,你可以这样做:
If you also want to move the magnifying glass icon, you can do this:
text.leftView = nil;
text.rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search_icon.png"]];
但您必须提供search_icon.png图片。
But you will have to provide the search_icon.png image.
这篇关于是否可以更改UISearchBar占位符的对齐方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!