修改UISearchDisplayController的searchBar的cancel按钮文字为中文"取消" 设置statusBar的背景色和searchBar背景色一致

bug.gif

]initWithFrame:CGRectMake(0, 0, VGScreenW, 20)];
//默认让imageViewStatus隐藏
_imageViewStatus.hidden = YES;
}
return _imageViewStatus;
}

  • (void)initSearchBar {
    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 64)];
    self.searchBar.backgroundImage = [UIImage imageFormColor:[UIColor clearColor] frame:CGRectMake(0, 0, VGScreenW, 64)];
    self.searchBar.barStyle = UIBarStyleDefault;
    self.searchBar.backgroundColor = [UIColor clearColor];
    [self.searchBar setBarTintColor:[UIColor colorWithWhite:0.9 alpha:0]];
    self.searchBar.translucent = YES;
    self.searchBar.delegate = self;
    self.searchBar.placeholder = TipPlaceHolder;
    self.searchBar.keyboardType = UIKeyboardTypeDefault;
    [self.mapView addSubview:self.searchBar];
    }
    //
  • (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
    controller.searchBar.backgroundColor = [UIColor whiteColor];
    controller.searchBar.showsCancelButton = YES;
    self.imageViewStatus.backgroundColor = [UIColor redColor];
    self.imageViewStatus.hidden = NO;//设置imageViewstatus显示
    [self.imageViewStatus setImage:[UIImage imageNamed:@"statusBarView"]];
    [self.navigationController.navigationBar.window addSubview:self.imageViewStatus];
    [self.navigationController.navigationBar.window bringSubviewToFront:self.imageViewStatus];
    for (id searchbutton in controller.searchBar.subviews) {
    UIView *view = (UIView *)searchbutton;
    UIButton *cancelButton = (UIButton *)[view.subviews objectAtIndex:2];
    cancelButton.enabled = YES;
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];//文字
    [cancelButton setTitleColor:VGColor(255, 150, 0) forState:UIControlStateNormal];
    break;
    }
    }
    //点击取消按钮时设置imageViewStatus隐藏
  • (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    self.imageViewStatus.hidden =YES;
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 转自:http://www.code4app.com/blog-866962-1317.html1、设置UILab...
    MMOTE阅读 1,700评论 1 1
  • //设置尺寸为屏幕尺寸的时候self.window = [[UIWindow alloc] initWithFra...
    LuckTime阅读 839评论 0 0
  • 作者唯一QQ:228544117。。。。。 =========后面的都要新建一个文章 AppDelegate.h ...
    CC_iOS阅读 966评论 0 0
  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    十年一品温如言1008阅读 1,741评论 0 3
  • 喜欢摄影,对它的热爱超乎想象, 喜欢记录,暂停生活中的每一瞬间, 喜欢时间,现在二十三点十四分, ...
    zy不变阅读 183评论 0 4