简体   繁体   English

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

[英]Unable to change text color in a search bar for iOS 7

I need to change the text color in an UISearchBar text field. 我需要更改UISearchBar文本字段中的文本颜色。 I tried the two answers in this post: 我在这篇文章中尝试了两个答案:

UISearchBar text color change in iOS 7 iOS 7中的UISearchBar文本颜色更改

But the text remains in its default gray color. 但文本仍保持默认的灰色。 I set that code in the viewDidLoad method. 我在viewDidLoad方法中设置了该代码。 What can I be missing? 我能错过什么? Did somebody have this same problem? 有人有同样的问题吗?

Thanks 谢谢

[[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
// 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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM