ios - 修改 UISearchBar 取消按钮字体文字颜色和样式

标签 ios uisearchbar

有没有办法在不子类化搜索栏的情况下更改 UISearchBar 取消按钮的文本字体和颜色?

最佳答案

当包含在 UISearchBar 中时,您可以通过更改 UIBarButtonItem 的外观来更改取消按钮样式。

例如,

[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                      [UIColor blueColor], 
                                                      UITextAttributeTextColor, 
                                                      [UIColor darkGrayColor], 
                                                      UITextAttributeTextShadowColor, 
                                                      [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], 
                                                      UITextAttributeTextShadowOffset,
                                                      nil] 
                                            forState:UIControlStateNormal];

关于ios - 修改 UISearchBar 取消按钮字体文字颜色和样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11572372/

相关文章:

ios11:导航栏中的 UISearchBar

cocoa-touch - iPad表格 View 上的UISearchBar消失在导航 Controller 栏下方

ios - ios搜索栏能够添加取消图像但不正确

ios - 防止IOS通知菜单下滑

ios - 无法使用 ADT 编译 64 位 AIR ANE

ios - UITableViewCell 中的标记

ios - 即使我做了深度清理并重新安装 Xcode,也无法在设备上运行 Xcode 项目,钥匙串(keychain)总是出错

iphone - 适用于 iOS 的 ARC 兼容图表框架

ios - UISearchDisplayController 如何窃取 UISearchBar 事件

ios - UIPickerView 和 UISearchController 不显示数据