如何在iOS7中右对齐UISearchbar的文本 [英] How to right align text of UISearchbar in iOS7
本文介绍了如何在iOS7中右对齐UISearchbar的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你能告诉我如何在iOS 7中正确对齐UISearchbar文本吗? ,我在iOS6中使用它,但现在它在iOS7中不起作用:
Could you tell me how to right align UISearchbar text in iOS 7? , I was using this in iOS6 but now it does not work in iOS7:
//hacking search bar
UITextField *searchField;
for (UIView *subview in self.searchBar.subviews)
{
if ([subview isKindOfClass:[UITextField class]]) {
searchField = (UITextField *)subview;
break;
}
}
if (searchField) {
searchField.textAlignment = NSTextAlignmentRight;
}
推荐答案
现在为时已晚,但如果任何人仍然想知道解决方案,然后你可以遵循这个。
It's too late, but if anyone is still wondering the solution, then you can follow this.
UITextField *searchTextField = [searchBarController.searchBar valueForKey:@"_searchField"];
您可以使用上面的代码获取搜索字段。现在只需使用您想要使用的属性,例如。
You can get the search field using above code. Now simply use the properties you want to use, like.
searchTextField.layer.cornerRadius = 10.0f;
searchTextField.textAlignment = NSTextAlignmentRight;
这篇关于如何在iOS7中右对齐UISearchbar的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文