6

我一直在阅读以更改导航栏上的默认颜色我只需要将 appdelegate 中的第一个方法更新为此

self.window.rootViewController.navigationController.navigationBar.tintColor = [UIColor whiteColor];

但它似乎不起作用,所以我也尝试在 firstview 的 viewDidLoad 方法中设置它:

self.parentViewController.navigationController.navigationBar.tintColor = [UIColor whiteColor];

这也不起作用。我怎样才能改变这个?

4

4 回答 4

6

不要使用self.parentViewController,但是self

self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
于 2012-06-02T18:12:25.857 回答
1

当 iphone 5 来时,我们必须设置两种设备类型。所以用这个

if([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
    //iOS 5 new UINavigationBar custom background
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbg_ForiPhone5_Imagename.png"] forBarMetrics: UIBarMetricsDefault];
} else {
    [self.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navbg_ForOtherIphone_Imagename.png"]] atIndex:0];
}
于 2012-12-19T11:58:53.660 回答
1

在IOS7你可以试试这个:

[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];

您可以按照以下步骤操作:

我创建了一个新UINavigationController的例子UIDemoNavController,结果是:

- (void)viewDidLoad{
    [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];  
    [super viewDidLoad];
}

这是完整的演示课程:

#import "UIDemoNavController.h"

@interface UIDemoNavController()

@end

@implementation UIDemoNavController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {}
    return self;
}

- (void)viewDidLoad{
    [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning{
    [super didReceiveMemoryWarning];
}

@end
于 2014-05-02T13:34:24.557 回答
0

Tryself.navigationController.navigationBar.tintColor = [UIColor whiteColor];
UIViewController类有一个属性navigationController,它返回它嵌入的导航控制器,不管它有多深,否则它返回nil

于 2012-06-02T18:11:13.623 回答