2014-09-26 39 views
2

在IOS搜索栏我能够添加取消图像和删除文本,但一个问题是当我searchBar酒吧色调清晰后,我的图像不显示,我必须清除在UI
色彩条的颜色我要在搜索栏添加图像取消按钮 这里是我的代码ios搜索栏能够添加取消图像,但不正确

-(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]; 


    } 
} 

enter image description here

清除色彩条的颜色后 enter image description here

请给我解决方案............... 是否有希望请帮帮我........... 请帮忙,有没有5天完成和我没有任何解决方案

+0

您是否解决了此问题? – 2016-11-28 06:59:47

回答

0

把这个方法放在你的搜索栏代表。您无需添加图像

(void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar1 
{ 
    [searchBar setShowsCancelButton:YES animated:YES]; 
} 
+0

我已将此代码添加到顶部,但无法正常工作 – 2014-09-26 10:48:36

+0

您是否可以为我添加更多代码来验证至少 – iOSdev 2014-09-26 11:07:03