我在导航栏中嵌入了一个搜索栏。 我能够改变背景颜色,但对于我的生活不能改变文字颜色。 我的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];有什么建议么???
I have a searchbar embedded in a navigationbar. I'm able to change background color, but for the life of me cannot change text color. I have the following code in my viewdidload. What is missing to get the text to change?
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;I've read that the following should work but doesn't:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor blueColor]];I've also tried:
itemSearchBar.tintColor = [UIColor redColor]; txfSearchField.textColor = [UIColor redColor];Any suggestions???
最满意答案
我认为您正在查看占位符文本的颜色,而不是在文本字段中键入任何内容。 否则,您的代码似乎是正确的。 方法
txfSearchField.textColor = [UIColor redColor]必须工作。 在字段中键入任何内容,您将看到红色。
I think you are looking at the color of placeholder text and not typing anything in the textfield. Otherwise, your code seems correct. The method
txfSearchField.textColor = [UIColor redColor]must work. Type anything in the field and you will see red color.
更多推荐
发布评论