1

现在,我必须在每次推送视图之前执行以下操作

    _homeNavigationController.navigationBar.barStyle = UIBarStyleBlack;
    _homeNavigationController.navigationBar.tintColor = nil;     

我想使用带图案的图像将颜色设置为不同的颜色。

那么有没有简单的方法呢?

4

2 回答 2

3

如果您使用的是 iOS 5,则可以使用外观协议。

[[UINavigationBar appearance] setBackgroundImage:myImage];

文档可以在这里找到:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAppearance_Protocol/Reference/Reference.html

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UINavigationBar_Class/Reference/UINavigationBar.html#//apple_ref/doc/uid/TP40006887

于 2012-05-17T23:07:07.707 回答
1

如果您想使用自定义色调(内置常量除外),请使用以下代码:

在全球某处定义这些。

#define RGBCOLOR(r,g,b)         [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define COLOR_NAVBAR_TINT           RGBCOLOR(82, 154, 217)
#define COLOR_TOOLBAR_TINT          RGBCOLOR(82, 154, 217)

将此添加到您的 AppDelegate.m,然后在您的应用程序初始化期间调用它:

- (void)initializeGlobalTheme {
    [[UINavigationBar appearance] setTintColor:COLOR_NAVBAR_TINT];
    [[UIToolbar appearance] setTintColor:COLOR_TOOLBAR_TINT];
}
于 2012-05-17T23:28:07.627 回答