去掉搜索框(searchBar)的背景框

使用iOS系统自带的searchBar。

_searchBar = [UISearchBar new];
_searchBar.placeholder = @"输入您想查询的内容";
_searchBar.delegate = self;
[self.view addSubview:_searchBar];
[_searchBar mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.mas_offset(0);
    make.left.mas_offset(0);
    make.right.offset(-40);
    make.height.mas_equalTo(40);
}];

但是做出来后不是自己想要的那种效果修改背景框颜色,试了很多种方法都不太理想!用了下面的方法可以了! 

_searchBar.barTintColor = [UIColor whiteColor];

_searchBar.layer.borderWidth = 1;

_searchBar.layer.borderColor = [UIColor whiteColor].CGColor;

效果图:


修改searchbar上的输入框的样式,例如:改变搜索框中的placeholder的颜色。

UITextField *searchField = [_searchBar valueForKey:@"searchField"];
[searchField setValue:COLOR_MAIN_BG_BLUE forKeyPath:@"placeholderLabel.textColor"];// 改变搜索框中的placeholder的颜色
searchField.layer.borderColor = COLOR_TEXT_GRAY.CGColor;
searchField.layer.borderWidth = 0.5;
searchField.layer.cornerRadius = 5;

效果图:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值