简体   繁体   English

呈现的UINavigationController色彩不变

[英]Presented UINavigationController tint color not changing

    MyVC *vc = [[MyVC alloc] init];
vc.delegate = self;

UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
[nc.navigationBar setTintColor:[UIColor redColor]];
[self presentViewController:nc animated:true completion:^{}];

The navigation bar is black. 导航栏为黑色。 I present this from a navigation controller inside a tab bar controller which is created in my App Delegate. 我从在我的App Delegate中创建的选项卡栏控制器中的导航控制器中呈现此内容。 In my ApplicationDidFinishLaunchingWithOptions, I can control the color of the navigation controllers there. 在我的ApplicationDidFinishLaunchingWithOptions中,我可以控制那里的导航控制器的颜色。

Why is this navigation controller tint bar black? 为什么此导航控制器色调栏为黑色?

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

I would suggest you to use this if all of your NavigationBars are the same color. 如果所有的NavigationBar都是相同的颜色,我建议您使用此颜色。 Appearance property of an object sets uniformity on the function you apply on it. 对象的外观属性可为您应用的功能设置均匀性。

  • You can try to make custom class for UINavigationBar 您可以尝试为UINavigationBar创建自定义类

.h 。H

@interface CustomUINavigationBar : UINavigationBar {

}

@end

.m .m

@implementation CustomUINavigationBar

- (void)drawRect:(CGRect)rect {

    UIColor *color = [UIColor colorWithRed:0.023 green:0.14 blue:0.478 alpha:1];// for example
    self.tintColor = color;

}

@end

Also you can try to insert the below code in the didFinishLaunchingWithOptions: of AppDelegate.m 您也可以尝试将以下代码插入AppDelegate.m的didFinishLaunchingWithOptions:中

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

In iOS7 you have to use barTintColor property iOS7您必须使用barTintColor属性

[nc.navigationBar setBarTintColor:[UIColor redColor]];

instead of 代替

[nc.navigationBar setTintColor:[UIColor redColor]];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM