iOS UISearchBar的背景颜色修改


测试环境 :iOS 9.3


修改内部输入框的颜色为红色 ,背景颜色为绿色

UISearchBar * search = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 250,320, 44)];
    
    [self.view addSubview:search];
    
    // 经测试, 需要设置barTintColor后, 才能拿到UISearchBarTextField对象
    search.barTintColor = [UIColor greenColor];//这里修改的searchBar的背景颜色
    UITextField * searchTextField = [[[search.subviews firstObject] subviews] lastObject];

   // search.backgroundColor = [UIColor greenColor];
    [searchTextField setBackgroundColor:[UIColor redColor]];




你可能感兴趣的:(iOS)