我有以下代码可以更改 UISearchBar 中取消按钮的背景。
for( UIView *subview in self.searchBar.subviews ){
if ([subview isKindOfClass:[UIButton class]]) {
[(UIButton *)subview setEnabled:YES];
[(UIButton *)subview setTitle:@"New Button Text" forState:UIControlStateNormal];
((UIButton *)subview).tintColor = [UIColor colorWithRed:4/255.0 green:119/255.0 blue:152/255.0 alpha:1.0];
}
}
问题是这段代码在iOS7中不起作用!UISearchBar 中的视图结构发生了什么变化?
编辑:在这里测试,这是 UISearchBar 的新层次结构:
UISearchBar:
---UIView:
------UISearchBarBackground
------UISearchBarTextField
------UINavigationButton
问题是我无法测试if ([sub isKindOfClass:[UINavigationButton class]])
。此行会引发编译错误:Use of undeclared identifier: UINavigationButton