在IOS searchBar中,我可以添加取消图像并删除文字,但有一个问题是当我的搜索条形图色调清除之后我的图像没有显示,我必须在色调栏中清除用于UI的颜色
我必须在搜索栏取消按钮中添加图像
这是我的代码
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{
self.searchDisplayController.searchBar.showsCancelButton = YES;
UIButton *cancelButton;
UIView *topView = self.searchDisplayController.searchBar.subviews[0];
for (UIView *subView in topView.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UINavigationButton")]) {
cancelButton = (UIButton*)subView;
}
}
if (cancelButton) {
//Set the new title of the cancel button
[cancelButton setTitle:@" " forState:UIControlStateNormal];
// [cancelButton setBackgroundColor:[UIColor redColor]];
[cancelButton setImage:[UIImage imageNamed:@"close_icon.png"] forState:UIControlStateNormal];
}
}
清除色调条后的颜色
请给我解决方案............... 有希望请帮助我........... 请帮助,有5天完成,我没有任何解决方案
答案 0 :(得分:0)
将此方法放入搜索栏代理中。您无需添加图片
(void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar1
{
[searchBar setShowsCancelButton:YES animated:YES];
}