2014-10-30 70 views
0

我將搜索欄的佔位符顏色更改爲藍色,文本顏色更改爲白色。正常情況正常工作。UISearch欄文字顏色問題

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]; 
[[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor colorWithRed:131/255.0 green:169/255.0 blue:202/255.0 alpha:1.0] ]; 
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setBackgroundColor:[UIColor colorWithRed:42/255.0 green:93/255.0 blue:134/255.0 alpha:1.0]]; 

問題 當我設置文本

self.searchbar.text = @"Some text"; 

在搜索欄中顯示的文本採取佔位符顏色即藍色,但我想它採取白色。

回答

0

而不是「UILabel」爲您的文字顏色,使用「UITextField」:

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor colorWithRed:131/255.0 green:169/255.0 blue:202/255.0 alpha:1.0]]; 

和更多信息可以在this related question答案被發現。