在 iOS7 中,搜索图标和占位符文本总是出现在中间。我尝试将搜索栏中文本字段的文本对齐方式更改为左侧,但没有成功。 有什么方法可以使搜索栏搜索图标在 iOS7 中显示为左对齐
我尝试了以下几行,但没有用:
UITextField *txfSearchField = [_searchBar valueForKey:@"_searchField"];
txfSearchField.textAlignment = NSTextAlignmentLeft;
[_searchArticle setImage:image forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
UIimageView *im = [UIImageView alloc]init];
im.image = image;
txfSearchField.leftView =im;
最佳答案
无法更改搜索栏占位符文本的对齐方式,我尝试了很多“SO”答案,但没有人工作。最后我以这个解决方法结束了
在占位符文本的右边留一些空白
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
self.searchBar.placeholder = @"hello";
} else {
// Load resources for iOS 7 or later
self.searchBar.placeholder = @"hello ";
}
尽情享受吧!
关于iphone - UISearchBar 搜索图标在 iOS 7 中未左对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19289406/