如何在iOS7中更改UISearchBar的取消按钮色调颜色
问题描述:
我想将Textfield的色调颜色更改为蓝色,并取消UISearchBar的按钮色调颜色为白色。
I want to change tint color of Textfield to blue color and cancel button tint color of UISearchBar to white color.
我正在使用下面的代码。
I am using below code.
for (UIView *subView in searchBar.subviews)
{
for (UIView *ndLeveSubView in subView.subviews)
{
if([ndLeveSubView isKindOfClass:[UITextField class]])
{
[(UITextField *)subView setTintColor:[UIColor blueColor]];
}
else if ([ndLeveSubView isKindOfClass:[UIButton class]])
{
[(UIButton *)subView setTintColor:[UIColor whiteColor]];
}
}
}
但这会改变Textfield和取消按钮的色调为白色。任何人都可以建议另一种方法吗?
But this changes both Textfield and cancel button's tint color to white. Can any one suggest another method for it?
这是我得到的......
Here's what I am getting...
TextField的色调颜色也是白色.....
The tint color of TextField is also White.....
答
尝试这样的事情:
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,[NSValue valueWithUIOffset:UIOffsetMake(0, 1)],UITextAttributeTextShadowOffset,nil] forState:UIControlStateNormal];