UISearchBar占位符文本颜色/位置

时间:2015-10-05 10:52:02

标签: ios objective-c uisearchbar placeholder

但是,我已经应用了不同的补丁,但我无法修复UISearchbar的占位符文字位置和文字颜色。 enter image description here

但是当我输入某些内容时,它会显示在适当的位置。

是什么原因?

2 个答案:

答案 0 :(得分:0)

这是您可以更改占位符文字颜色的方法:

UITextField *searchField = [self.searchBar valueForKey:@"searchField"];
searchField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Some Text"];
UILabel *placeholderLabel = [searchField valueForKey:@"placeholderLabel"];
placeholderLabel.textColor = [UIColor blueColor];

对于位置,默认情况下,占位符文本垂直居中于UISearchBar。从截图中可以看出,文本末尾几乎没有新的行字符。

答案 1 :(得分:0)

UITextField上创建了一个类别,其中包含占位符文本。我刚刚纠正了框架,现在一切正常,甚至解决了颜色问题。

相关问题