iOS UISearchBar的背景顏色修改
阿新 • • 發佈:2019-02-10
測試環境 :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]];