iOS 修改搜索框的样式为白色

    //思路:正常SearchBar有一个灰色环绕边框,在searchBar外层加一个白色的背景,这个背景只够包围searchBar的搜索框部分
    //同时调节searchBar的frame让它正好在白色背景呢,这样灰色的边框就在背景外面不能被显示出来了
    UIView *searchBGView = [[UIView alloc] initWithFrame:CGRectMake(8, ORIGIN_Y + 7, DEVICE_W - 8 * 2, 28)];
    searchBGView.backgroundColor = [UIColor whiteColor];
    searchBGView.layer.borderColor = [UIColor colorWithRed:242/255.0f green:242/255.0f blue:242/255.0f alpha:1].CGColor;
    searchBGView.layer.borderWidth = 0.5f;
    searchBGView.layer.masksToBounds = YES;
    searchBGView.layer.cornerRadius = 4;
    
    UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(-10, 0, searchBGView.frame.size.width + 20, searchBGView.frame.size.height)];
    searchBar.delegate = self;
    searchBar.backgroundColor = C_white;
    searchBar.returnKeyType = UIReturnKeySearch;
    searchBar.showsCancelButton = NO;
    searchBar.showsSearchResultsButton = NO;
    searchBar.placeholder = @"点击搜索品牌";
    
    [self.view addSubview:searchBGView];
    [searchBGView addSubview:searchBar];


转载于:https://my.oschina.net/u/1782374/blog/634761

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值