Gav*_*avy 104
我找到了一种更简单的方法来改变标题的颜色:iOS7:
UIBarButtonItem *button =
[[UIBarButtonItem alloc] initWithTitle:@"Title"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
[button setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor], NSForegroundColorAttributeName,nil]
forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
和以前的iOS7:
UIBarButtonItem *button =
[[UIBarButtonItem alloc] initWithTitle:@"Title"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
[button setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor], UITextAttributeTextColor,nil]
forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
有两种方法可以更改文本显示的UIBarButtonITem的颜色.
1)
[barButtonITem setTintColor:[UIColor redColor]];
Run Code Online (Sandbox Code Playgroud)
2)或者你可以使用任何UIColor类方法.这是非常有效的解决方案.对于iOS 7,您可以使用NSForegroundColorAttributeName并且可以使用
barButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor clearColor],NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31956 次 |
| 最近记录: |