浏览了文档,我找不到任何可以更改UISearchBar颜色的东西。有谁知道怎么改变它吗?没有任何textColor属性:/
Thx
发布于 2015-01-28 09:15:46
适用于iOS 7及更高版本:
    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{
                                 NSForegroundColorAttributeName : [UIColor whiteColor],
                                 NSFontAttributeName : [UIFont systemFontOfSize:15]
                                 }];您也可以删除未使用的属性。
更新。由于appearanceWhenContainedIn在iOS 9中已被弃用,请参阅下面的反对答案:https://stackoverflow.com/a/38893352/2799722
发布于 2010-08-24 06:02:05
您可以执行以下操作:只需从SearchBar获取searchField属性,然后更改其textColor属性。
UITextField *searchField = [searchbar valueForKey:@"_searchField"];
searchField.textColor = [UIColor redColor]; //You can put any color here.就这样!现在,您可以以任何可能的方式操作textField。
发布于 2014-03-15 16:32:15
iOS 8:请参阅https://stackoverflow.com/a/28183058/308315
iOS 6/ 7:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor redColor]];https://stackoverflow.com/questions/1407833
复制相似问题