请检查我的下面的代码,我使用一个navigationbar
searchbar
,searchbar
有一个文本字段,现在我要更改textfield
的文字颜色我做了一个下面的代码,但它没有工作,所以请帮助纠正它。
[[UISearchBar appearanceWhenContainedInInstancesOfClasses:@[[UINavigationBar class]]]setTintColor:[UIColor whiteColor]];
[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]]setTextColor:[UIColor whiteColor]];
答案 0 :(得分:0)
如果您使用的是本机UISearchbar
控件,则可以使用下面的代码更改文本颜色
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];
答案 1 :(得分:0)
试试这个,
NSArray *searchBarSubViews = [[self.searchBar.subviews objectAtIndex:0] subviews];
for (UIView *view in searchBarSubViews) {
if([view isKindOfClass:[UITextField class]])
{
UITextField *txt = (UITextField*)view;
UIImageView *imgView = (UIImageView*)textField.leftView;
imgView.image = [imgView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
imgView.tintColor = [UIColor whiteColor];
txt.backgroundColor = [UIColor blackColor];
txt.textColor = [UIColor RedColor];
UIButton *btnClear = (UIButton*)[textField valueForKey:@"clearButton"];
[btnClear setImage:[btnClear.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
btnClear.tintColor = [UIColor whiteColor];
}
}