我尝试使用以下代码将UISearchbar的条形颜色设置为一种颜色,而将tintColor(光标和取消按钮)设置为另一种颜色:
searchbar.barTintColor = color1;
searchbar.tintColor = color2;
barTintColor已正确应用。
问题是:取消按钮的文本不可见,但如果在storyboard中尝试相同的操作(将batTintColor和tintColor应用于UISearchbar),则一切都按预期工作。
我尝试使用以下代码将UISearchbar的条形颜色设置为一种颜色,而将tintColor(光标和取消按钮)设置为另一种颜色:
searchbar.barTintColor = color1;
searchbar.tintColor = color2;
barTintColor已正确应用。
问题是:取消按钮的文本不可见,但如果在storyboard中尝试相同的操作(将batTintColor和tintColor应用于UISearchbar),则一切都按预期工作。
我注意到当取消按钮的状态为“normal”时,它是不可见的,因此我找到了这段代码来解决问题,但我认为这不是预期的方法。
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor greenColor]} forState:UIControlStateNormal];