5

我需要更改UISearchBar文本字段中的文本颜色。我在这篇文章中尝试了两个答案:

iOS 7 中的 UISearchBar 文本颜色变化

但文本仍保持其默认的灰色。我在方法中设置了该代码viewDidLoad。我能错过什么?有人有同样的问题吗?

谢谢

4

2 回答 2

2
// Get the instance of the UITextField of the search bar
UITextField *searchField = [self.searchBar valueForKey:@"_searchField"];

// Change search bar text color
searchField.textColor = [UIColor blueColor];
于 2014-05-12T21:40:08.053 回答
2
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor blueColor]];

//This is done in Xcode 5.0 and its working btw i don't know whether it works with previous versions of Xcode or not....
// Also I wrote this method in viewDidLoad
于 2014-04-07T22:15:32.127 回答