如何更改 UISearchBar 取消按钮的文本颜色?

How can I change the text color of a UISearchBar's cancel button?

我的 iOS 应用程序中有一个 UISearchController。当用户点击其 UISearchBar 时,键盘会弹出并显示一个取消按钮。如何更改取消按钮的文本颜色?

试试这个:

(UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self])).tintColor = UIColor.blackColor()

只需设置搜索栏的色调即可。 :) 就这么简单。