hti*_*inn 69
您可以通过更改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];
Run Code Online (Sandbox Code Playgroud)
Chr*_*irk 15
let attributes = [
NSForegroundColorAttributeName : UIColor.white,
NSFontAttributeName : UIFont.systemFont(ofSize: 17)
]
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(attributes, for: .normal)
Run Code Online (Sandbox Code Playgroud)
Jav*_*cio 11
斯威夫特 5
let attributes:[NSAttributedString.Key: Any] = [
.foregroundColor: UIColor.black,
.font: UIFont.systemFont(ofSize: 17)
]
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(attributes, for: .normal)
Run Code Online (Sandbox Code Playgroud)
如果您只想修改取消按钮,可以通过以下方式进行:
if let cancelButton = searchBar.valueForKey("cancelButton") as? UIButton {
cancelButton.setTitle(<your_string>, forState: <UIControlState>)
cancelButton.setTitleColor(<your_uicolor>, forState: <UIControlState>)
cancelButton.setAttributedTitle(<your_nsattributedstring>, forState: <UIControlState>)
}
Run Code Online (Sandbox Code Playgroud)
searchBar你的UISearchBar对象在哪里。
基于 htinlinn 的回答,这是我在viewDidLoad使用 iOS 7 中的搜索栏的视图控制器方法中使用的:
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil]
setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]
forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20283 次 |
| 最近记录: |