有没有办法更改UISearchBar取消按钮的文本字体和颜色,而不需要创建搜索栏的子类化?
发布于 2012-07-20 12:21:57
当UIBarButtonItem
包含在UISearchBar
中时,可以通过更改其外观来更改取消按钮样式。
例如,
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor blueColor],
UITextAttributeTextColor,
[UIColor darkGrayColor],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
nil]
forState:UIControlStateNormal];
发布于 2016-12-08 22:54:35
Swift 3
let attributes = [
NSForegroundColorAttributeName : UIColor.white,
NSFontAttributeName : UIFont.systemFont(ofSize: 17)
]
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(attributes, for: .normal)
发布于 2014-02-23 11:10:33
根据htinlinn的回答,这是我在iOS 7中使用搜索栏的视图控制器的viewDidLoad
方法中使用的方法:
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil]
setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]
forState:UIControlStateNormal];
https://stackoverflow.com/questions/11572372
复制相似问题