简体   繁体   中英

how to change backbutton color iOS7

I've been developed an app for iOS7 which has this design

在此输入图像描述

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:

[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:

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

and, of course, replacing [UIColor redColor] with whatever color you want.

Put this code in your App Delegate:

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.

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

迅速:

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.
  • Because the static tintColor property was removed in latest version of Interface builder. 单击“+”,在KeyPath中添加tintColor,设置“类型”颜色并添加颜色。

You can set it in IB directly:

在此输入图像描述

-(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]];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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