在iOS7中测试的UINavigationBar设置tintcolor无法正常工作?

vee*_*eev 22 iphone objective-c uinavigationcontroller tintcolor ios7

我有一个应用程序有一个UINavigationBar,我已将色调颜色设置为黑色,如下所示:

self.navigationController.navigationBar.tintColor = [UIColor blackColor];`
Run Code Online (Sandbox Code Playgroud)

我在IOS 6测试了它,它是黑色的.但是,当我在iOS 7中尝试使用相同的应用程序时,它显示为默认导航栏.

正如标题所说,它不起作用吗?

Hec*_*tos 22

您需要设置barTintColor属性.

您可以使用Tint(barTintColor)字段为导航栏背景指定自定义色调颜色.默认背景色调颜色为白色.

来自iOS7文档:https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/UIKitUICatalog/UINavigationBar.html#//apple_ref/doc/uid/TP40012857-UINavigationBar-SW1


Iri*_*siu 16

Fernando和sanjana的答案有关键,但我只是添加一些内容以使其更清晰,更明显.

导航栏有两个属性

  • tintColor
  • barTintColor

当你不考虑iOS 7术语时,这有点误导.

tintColor更改导航栏上按钮的颜色.要更改背景颜色,您需要设置属性barTintColor.

self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
self.navigationController.navigationBar.tintColor = [UIColor greenColor];
Run Code Online (Sandbox Code Playgroud)

此代码段将为您提供带绿色按钮的白色导航栏.


Div*_*iya 9

我使用下面的代码来改变iOS7中导航栏的色调,我在app delegate"applicationDidFinishLaunch"方法中添加了这个,它的工作正常对我来说:

/* ios 7 Change */
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
    {
        [[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x4B678B)];
        NSShadow *shadow = [[NSShadow alloc] init];
        shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
        shadow.shadowOffset = CGSizeMake(0, 1);
        [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                                               [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
                                                               shadow, NSShadowAttributeName,
                                                               [UIFont fontWithName:@"Helvetica Neue" size:21.0], NSFontAttributeName, nil]];
        // self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
        //[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
        [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

    }
Run Code Online (Sandbox Code Playgroud)