UISearchBar *searchBar = [UISearchBar new];
UITextField *searchField = [searchBar valueForKey:@"_searchField"];
// 输入文本颜色
searchField.textColor = [UIColor blackColor];
// 默认文本颜色
[searchField setValue:[UIColor blackColor] forKeyPath:@"_placeholderLabel.textColor"];
//第2种方法
//设置属性字符串,设置好想要的颜色和文本
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"默认文本" attributes:[NSDictionary dictionaryWithObject:UIColorFromRGB(198.0, 198.0, 198.0) forKey:NSForegroundColorAttributeName]];
//修改默认文本
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setAttributedPlaceholder:attributedString];
本文详细介绍了如何在iOS开发中使用UISearchBar组件,并通过代码示例展示了如何自定义其输入文本颜色及默认文本颜色。

5446

被折叠的 条评论
为什么被折叠?



