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

时间:2014-06-16 10:53:21

标签: ios iphone ios7 uisearchbar

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控制器的搜索栏中设置颜色,但我无法正确设置它... this is the screen shot of search display controller请告诉我解决方案...谢谢

i want this type of color in searchbar display controller's searchbar

2 个答案:

答案 0 :(得分:0)

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

- (void)setSearchFieldBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state

请参阅 https://developer.apple.com/library/ios/documentation/uikit/reference/UISearchBar_Class/Reference.html#//apple_ref/occ/instm/UISearchBar/searchFieldBackgroundImageForState

答案 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] ];