0
我有一個搜索欄嵌入在導航欄中。我能夠改變背景顏色,但對於我的生活不能改變文字顏色。我在我的viewdidload中有以下代碼。什麼是缺少讓文字改變?無法更改搜索欄文本顏色,但我可以更改背景顏色
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];
任何建議???
謝謝,您的回答促使我實際輸入搜索欄以查看顏色變化。它還指示我調查我在此處使用的佔位符文本顏色更改:http://stackoverflow.com/questions/1340224/iphone-uitextfield-change-placeholder-text-color – Ryasoh 2014-09-28 23:35:03