【发布时间】:2009-11-05 10:19:55
【问题描述】:
我想更改UINavigationBar titleColor。
我还想更改UINavigationBar backButton 的textColor。
我正在使用 iPhone Os sdk 3.1.2
【问题讨论】:
标签: iphone objective-c uinavigationcontroller uinavigationbar uibarbuttonitem
我想更改UINavigationBar titleColor。
我还想更改UINavigationBar backButton 的textColor。
我正在使用 iPhone Os sdk 3.1.2
【问题讨论】:
标签: iphone objective-c uinavigationcontroller uinavigationbar uibarbuttonitem
这对我有用。
使用它您可以更改所有导航按钮的颜色:
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];
将 redColor 替换为以下内容以调整按钮的颜色:
colorWithRed:0/255.0 green:144/255.0 blue:200/255.0 alpha:1.0// pick your color using this
一定要把它放在推送的视图控制器中。不是您希望看到此后退按钮颜色的视图控制器。
【讨论】:
这个问题的一部分has already been answered。
然后,要更改后退按钮标题颜色,我建议创建一个带有标签的自定义按钮:
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:yourViewWithColoredText];
navigationItem.leftBarButtonItem = buttonItem; // assign it as the left button
yourViewWithColoredText 应该是包含彩色文本的自定义视图。
然后根据你的需要,你可以让它看起来像一个标准的后退按钮。
【讨论】:
您可以将 UINavigationBar.h 中定义的 titleView 设置为:
@property(nonatomic,retain) UIView *titleView;
// Custom view to use in lieu of a title. May be sized horizontally. Only used when item is topmost on the stack.
用你想要的任何颜色弹出你自己的 UILabel。
【讨论】:
UIBarButtonItem *button = [[UIBarButtonItem alloc] init];
[button setTintColor:[UIColor redColor]];
【讨论】:
在 iOS 5 和 6 上将 title 设置为 UINavigationBar
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:UITextAttributeTextColor]];
在 iOS 7 上
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor blackColor]};
在所有UIBarButtonItem上设置textColor
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor blackColor], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState: UIControlStateNormal];
【讨论】: