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

5

我知道如何在iOS 6中更改导航栏的色调:

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

我正在APPDelegate页面添加以下代码。 现在我想在iOS 7中做到这一点,但是上面的代码不起作用。 我在网上搜索了一下,找到了一个解决方法。通过为每个页面添加以下函数,我可以更改导航颜色。
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0];

我需要一个能够添加到APPDelegate函数中的函数。请帮我解决这个问题。

https://dev59.com/n2Mk5IYBdhLWcg3w0hM- - Rajneesh071
5个回答

14

为什么不要使用 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]];
}

外观问题是全局的,这对我来说不起作用,因为在运行此代码后,导航栏上的颜色不正确会导致大量错误。我需要将其设置在实际实例上... - LightningStryk
雷所说的。使用 respondsToSelector 进行版本检查可能会更好。 - user1898829
如果您只需要更改当前导航栏的外观,可以使用以下代码: self.navigationController.navigationBar.tintColor = [UIColor anyColor]; self.navigationController.navigationBar.barTintColor = [UIColor anyColor]; - Islam

7
您可以在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]];

2

使用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]];
 }

0
在Swift中,我想要更改电子邮件弹出窗口中“取消”和“发送”按钮的色调颜色。它非常有效。
(UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.self])).tintColor = UIColor.whiteColor()

-1
尝试使用[self.navigationController.navigationBar setTranslucent:NO];

他不想改变导航栏的半透明效果。 - mcont

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接