iOS 7 UIBarButton back button arrow color

后端 未结 17 1886
情话喂你
情话喂你 2020-12-04 06:30

I\'m trying to change the back button arrow

\"enter

I\'m currently using the

相关标签:
17条回答
  • 2020-12-04 06:31

    Inside the rootViewController that initializes the navigationController, I put this code inside my viewDidAppear method:

    //set back button color
    [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];
    //set back button arrow color
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    
    0 讨论(0)
  • 2020-12-04 06:31

    You can set the tintColor property on the button (or bar button item) or the view controller's view. By default, the property will inherit the tint from the parent view, all the way up to the top level UIWindow of your app.

    0 讨论(0)
  • 2020-12-04 06:35

    It is possible to change only arrow's color (not back button title's color) on this way:

    [[self.navigationController.navigationBar.subviews lastObject] setTintColor:[UIColor blackColor]];
    

    Navigation bar contains subview of _UINavigationBarBackIndicatorView type (last item in subviews array) which represents arrow.

    Result is navigation bar with different colors of back button arrow and back button title

    0 讨论(0)
  • 2020-12-04 06:40

    To change the back button chevron color for a specific navigation controller*:

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

    *If you are using an app with more than 1 navigation controller, and you want this chevron color to apply to each, you may want to use the appearance proxy to set the back button chevron for every navigation controller, as follows:

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

    And for good measure, in swift (thanks to Jay Mayu in the comments):

    UINavigationBar.appearance().tintColor = UIColor.whiteColor()
    
    0 讨论(0)
  • 2020-12-04 06:40

    You have to set the tintColor of the entire app.

    self.window.tintColor = [UIColor redColor];
    

    Or in Swift 3:

    self.window?.tintColor = UIColor.blue
    

    Source: iOS 7 UI Transition Guide

    0 讨论(0)
  • 2020-12-04 06:40

    You can set the color on the entire app navigation's bar using the method

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
    (NSDictionary *)launchOptions{
        [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    }
    
    0 讨论(0)
提交回复
热议问题