Xcode UI搜索栏文本颜色问题

Xcode UI搜索栏文本颜色问题,xcode,uisearchbar,Xcode,Uisearchbar,我已将搜索栏占位符颜色更改为蓝色,文本颜色更改为白色。正常情况下工作正常 [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]; [[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] se

我已将搜索栏占位符颜色更改为蓝色,文本颜色更改为白色。正常情况下工作正常

[[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";
搜索栏中显示的文本采用占位符颜色,即蓝色,但我希望它采用白色。

使用UITextField,而不是UILabel作为文本颜色:

更多信息可在的答案中找到

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