我在导航栏里嵌入了一个搜索栏。我可以改变背景颜色,但对于我的生活不能改变文字颜色。在视图加载中有以下代码。没有什么东西可以让文字改变?
if(!itemSearchBar)
{
itemSearchBar = [[UISearchBar alloc] init];
[itemSearchBar setFrame:CGRectMake(0, 0, self.view.frame.size.width, 55)];
itemSearchBar.placeholder = @"What are you looking for?";
itemSearchBar.delegate = self;
UITextField *txfSearchField = [itemSearchBar valueForKey:@"_searchField"];
txfSearchField.backgroundColor = [UIColor colorWithRed:130/255.0 green:58/255.0 blue:23/255.0 alpha:1.0];
UISearchDisplayController *searchCon = [[UISearchDisplayController alloc]
initWithSearchBar:itemSearchBar
contentsController:self ];
[searchCon setActive:NO animated:YES];
self.searchDisplayController = searchCon;
self.searchDisplayController.delegate = self;
self.searchDisplayController.searchResultsDataSource = self;
self.searchDisplayController.searchResultsDelegate = self;
self.searchDisplayController.displaysSearchBarInNavigationBar=YES;我读到过以下内容应该有效,但并不有效:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor blueColor]];我也试过:
itemSearchBar.tintColor = [UIColor redColor];
txfSearchField.textColor = [UIColor redColor];有什么建议吗?
发布于 2014-09-28 21:59:00
我认为您是在查看占位符文本的颜色,而不是在文本字段中键入任何内容。否则,您的代码似乎是正确的。该方法
txfSearchField.textColor = [UIColor redColor] 一定有用。在字段中键入任何内容,您就会看到红色。
https://stackoverflow.com/questions/26088756
复制相似问题