简体   繁体   English

如何改变iOS7的按钮颜色

[英]how to change backbutton color iOS7

I've been developed an app for iOS7 which has this design 我已经为iOS7开发了一款具有这种设计的应用程序

在此输入图像描述

As you can see there's a blue arrow for all my BackButton (using UINavigationController and segues), I want to make them red, this is my code: 你可以看到我的所有BackButton都有一个蓝色箭头(使用UINavigationController和segues),我想把它们变成红色,这是我的代码:

[UIBarButtonItem   appearance]setTintColor:(UIColorFromRGB(toolbarTintColor))];
[[UIBarButtonItem  appearance]setTitleTextAttributes:textAtributesDictionaryNavBarButtons forState:UIControlStateNormal];

but results only applies to all other buttons, any help I'll appreciate 但结果只适用于所有其他按钮,任何帮助,我会很感激

thanks in advance for the support 在此先感谢您的支持

The tint color property of a navigation bar determines the color of the text of its bar button items in iOS 7. The code you are looking for is something like this: 导航栏的色调属性确定iOS 7中其条形按钮项的文本颜色。您要查找的代码如下所示:

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

and, of course, replacing [UIColor redColor] with whatever color you want. 当然,用你想要的任何颜色替换[UIColor redColor]

Put this code in your App Delegate: 将此代码放入App Delegate中:

Objective-C Objective-C的

[self.window setTintColor:[UIColor redColor]];

Swift 迅速

self.window?.tintColor = UIColor.redColor()

如果您不想更改整个应用程序中的色调颜色,只想在一个导航栏上执行此操作,请执行以下操作:

self.navigationController.navigationBar.tintColor = [UIColor redColor];

If you want the swift version. 如果你想要swift版本。

UINavigationBar.appearance().tintColor = UIColor.whiteColor()

Also, if you want to apply this style to all your navigation view controllers. 此外,如果要将此样式应用于所有导航视图控制器。 Put that code in your application didFinishLaunchingWithOptions method in your AppDelegate 将该代码放在AppDelegate中的应用程序didFinishLaunchingWithOptions方法中

迅速:

self.navigationController?.navigationBar.tintColor = UIColor.grayColor()
  • If you're using storyboard, then you've to add a user defined attribute for keyPath 'tintColor' under the class inspector pane. 如果您正在使用故事板,那么您需要在类检查器窗格下为keyPath“tintColor”添加用户定义的属性。
  • Because the static tintColor property was removed in latest version of Interface builder. 因为在最新版本的Interface builder中删除了静态tintColor属性。 单击“+”,在KeyPath中添加tintColor,设置“类型”颜色并添加颜色。

You can set it in IB directly: 您可以直接在IB中设置它:

在此输入图像描述

-(void)viewDidAppear:(BOOL)animated
{
   //set back button color
    [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];
    //set back button arrow color
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
}

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

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