iPhone Set Tint Color of Back Bar Button Item

前端 未结 10 759
清歌不尽
清歌不尽 2020-12-08 22:15

I am trying to set the tint color of the back button within a navigation controller, but nothing is working. I have tried

[self.navigationController.backBa         


        
相关标签:
10条回答
  • 2020-12-08 22:43

    You can't change the tint color of UINavigationItem directly. You have to change the tint color of navigation bar and your bar button will automatically change its color.

    Add these lines in your viewWillAppear method

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

    Or You can create a custom button and initialize your UIBarButtonItem as

    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:yourUIButton];
    
    0 讨论(0)
  • 2020-12-08 22:43

    Place the following code in AppDelegate that will set color for Back button globally

    //Set color of BackButtonItem globally
    
    [[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:5.0/255.0 
    green:127.0/255.0 blue:173.0/255.0 alpha:1.0]];
    

    This is supported in iOS 5 and above

    0 讨论(0)
  • 2020-12-08 22:51

    Swift way:

    It changes all items in the nav.

    In AppDelegate do something like this:

    let navControl = UINavigationBar.appearance()
        navControl.tintColor = UIColor.grayColor()
    
    0 讨论(0)
  • 2020-12-08 22:52

    This worked for me.

    [self.navigationController.navigationBar setTintColor:[UIColor redColor]];
    

    It is very similar to the second answer...

    0 讨论(0)
提交回复
热议问题