更改导航栏色调颜色 iOS 7。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19892000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:50:16  来源:igfitidea点击:

Change navigation bar tint color iOS 7.

iosios7uinavigationbaruicolorappdelegate

提问by Mayank Purwar

I know how to change navigation bat tint colour in iOS 6:

我知道如何在 iOS 6 中更改导航蝙蝠色调颜色:

[UINavigationBar appearance].tintColor = [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0];

I'm adding this code in APPDelegate page. Now I want to do this in iOS 7 but above code is not working. I searched on net. I got a solution. By adding below function to every page I can change navigation color.

我正在 APPDelegate 页面中添加此代码。现在我想在 iOS 7 中执行此操作,但上面的代码不起作用。我在网上搜索过。我得到了解决方案。通过向每个页面添加以下功能,我可以更改导航颜色。

self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0];

But I need a function which can add to APPDelegate function. Please help me to overcome this issue.

但我需要一个可以添加到 APPDelegate 函数的函数。请帮助我克服这个问题。

回答by Tarek Hallak

Why not to use setBarTintColorfor appearance proxy, you can do this:

为什么不setBarTintColor用于外观代理,您可以这样做:

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) 
{
    [[UINavigationBar appearance] setTintColor: [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0]];
}
else
{
    [[UINavigationBar appearance] setBarTintColor: [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0]];
}

回答by Hitesh Vaghela

you can add bellow code in appdelegate.m

您可以在 appdelegate.m 中添加波纹管代码

  if your app is navigation based

 // for background color
  [nav.navigationBar setBarTintColor:[UIColor blueColor]];

 // for change navigation title and button color
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary    dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,  [UIFont fontWithName:@"FontNAme" size:20], NSFontAttributeName, nil]];

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

回答by Lei

Using respondsToSelector for version checking may be better.

使用 RespondsToSelector 进行版本检查可能会更好。

if ([self.navigationBar respondsToSelector:@selector(setBarTintColor:)]) {
    [self.navigationBar setBarTintColor: [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0]];
 } else {
    [self.navigationBar setTintColor: [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0]];
 }

回答by alitosuner

In Swift, for me, I wanted to change tint color for the Cancel and Send buttons, when the e-mail pops up. And it worked great.

在 Swift 中,对我来说,当电子邮件弹出时,我想更改取消和发送按钮的色调颜色。而且效果很好。

(UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.self])).tintColor = UIColor.whiteColor()

回答by coder1010

Try [self.navigationController.navigationBar setTranslucent:NO];

尝试 [self.navigationController.navigationBar setTranslucent:NO];