无法更改iOS 7搜索栏中的文本颜色

时间:2013-11-03 21:01:28

标签: ios ios7 uitextfield uisearchbar textcolor

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

UISearchBar text color change in iOS 7

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

由于

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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];