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;
在上面的代码中我想在SearchBarDisplay控制器的搜索栏中设置颜色,但我无法正确设置它... 请告诉我解决方案...谢谢
答案 0 :(得分:0)
您应该能够设置背景图像以自定义搜索文本字段背景:
- (void)setSearchFieldBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state
答案 1 :(得分:0)
试试这个:
[sBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"search_bar"] forState:UIControlStateNormal];
[sBar setBackgroundImage:[UIImage imageNamed:@"search_bar_bg"]];
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor redColor] ];