美文网首页iOS
修改UISearchDisplayController的sear

修改UISearchDisplayController的sear

作者: NieFeng1024 | 来源:发表于2016-07-04 23:53 被阅读361次
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;
    }

相关文章

网友评论

  • crow226119:有没有办法拿到UISearchDisplayController自带的取消item的点击事件啊?
  • 33a02bf71691:有咩有办法设置取消那个界面下bar的背景色呢
    33a02bf71691:@swallowYan 恩好了 :smiley:
    NieFeng1024:@重复昵称 设置过透明,应该可以实现其他颜色设置

本文标题:修改UISearchDisplayController的sear

本文链接:https://www.haomeiwen.com/subject/vslhjttx.html