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];
相关文章
相关标签/搜索