iPhone Set Tint Color of Back Bar Button Item

前端 未结 10 788
清歌不尽
清歌不尽 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条回答
  •  Happy的楠姐
    2020-12-08 22:40

    I believe barButtonItem is read-only. (I'm not too sure about this, someone correct me if I'm wrong)

    To give a tint colour to these buttons, this is what I would do:

    In your App Delegate, add these lines of code:

    UIBarButtonItem *barButtonAppearance = [UIBarButtonItem appearance];
    [barButtonAppearance setTintColor:[UIColor redColor]]; // Change to your colour
    

    The first line sets an appearance proxy, so I believe this works too, if you like less code:

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

    I hope this works for you! (This changes all instances of UIBarButtonItem)

提交回复
热议问题