Ios 无法在搜索栏显示控制器的搜索栏中设置颜色

Ios 无法在搜索栏显示控制器的搜索栏中设置颜色,ios,iphone,ios7,uisearchbar,Ios,Iphone,Ios7,Uisearchbar,在上面的代码中,我想在SearchBarDisplay控制器的搜索栏中设置颜色,但我无法正确设置。。。请告诉我解决方案…谢谢 您应该能够设置背景图像以自定义搜索文本字段背景: UISearchBar *searchBar = [[UISearchBar alloc] init]; [searchBar setTranslucent:NO]; searchBar.barTintColor=[UIColor colorWithRed:92.0/255.0 green:122.0/255.0 b

在上面的代码中,我想在SearchBarDisplay控制器的搜索栏中设置颜色,但我无法正确设置。。。请告诉我解决方案…谢谢


您应该能够设置背景图像以自定义搜索文本字段背景:

UISearchBar *searchBar = [[UISearchBar alloc] init];

[searchBar setTranslucent:NO];


searchBar.barTintColor=[UIColor colorWithRed:92.0/255.0 green:122.0/255.0 blue:178.0/255.0 alpha:1.0];

searchBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44);


self.searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar
                                                                     contentsController:self];

 self.searchDisplayController.searchResultsDelegate = self;

 self.searchDisplayController.searchResultsDataSource = self;


 self.searchDisplayController.delegate = self;
看 :

试试这个:

- (void)setSearchFieldBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state
   [sBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"search_bar"] forState:UIControlStateNormal];

   [sBar setBackgroundImage:[UIImage imageNamed:@"search_bar_bg"]];

   [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor redColor] ];