美文网首页
UISearchBar的各种设置

UISearchBar的各种设置

作者: 一点坚持心 | 来源:发表于2016-12-27 16:40 被阅读0次

    self.searchView = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];

    [self.searchView becomeFirstResponder];

    self.searchView.showsCancelButton = YES;

    //首先是取消按钮的中文还是英文字

    for(UIView *view in  [[[self.searchView subviews] objectAtIndex:0] subviews]) {

    if([view isKindOfClass:[NSClassFromString(@"UINavigationButton") class]]) {

    UIButton * cancel =(UIButton *)view;

    [cancel setTitle:@"取消" forState:UIControlStateNormal];

    cancel.titleLabel.font = [UIFont systemFontOfSize:14];

    }

    }

    //修改搜索框里面提示字的颜色和大小

    UITextField *searchField = [self.searchView valueForKey:@"_searchField"];

    //这里是搜索框的圆角

    searchField.layer.cornerRadius = 15.0f;

    searchField.layer.masksToBounds = YES;

    //搜索框的背景色,设置的就是看上去比较深颜色的部分

    searchField.backgroundColor = [UIColor colorWithRed:21/255.0 green:144/255.0 blue:91/255.0 alpha:1.0f];

    //这个是修改水印文字字体的颜色

    [searchField setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];

    //修改水印文字的大小

    [searchField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];

    UIImage* searchBarBg = [self GetImageWithColor:[UIColor redColor] andHeight:32];

    //设置文本框背景,就是红色的部分

    [self.searchView setSearchFieldBackgroundImage:searchBarBg forState:UIControlStateNormal];

    相关文章

      网友评论

          本文标题:UISearchBar的各种设置

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