Setting UINavbar Backbutton Color

34 views
Skip to first unread message

William Frowine, PMP

unread,
May 20, 2012, 8:35:15 PM5/20/12
to pdx-cocoa...@googlegroups.com
Hello All:

I have a view where the view is pushed from the master view using a UINavigation controller.

I am wondering how you could change the color of the "Back Button" that takes you back to the parent view.  

I tried the following:

self.navigationController.navigationItem.leftBarButtonItem.tintColor = [UIColor redColor];

    


But it didn't do anything.  Any thoughts?


Thanks!

Doug Mason

unread,
May 21, 2012, 3:40:28 AM5/21/12
to pdx-cocoa...@googlegroups.com
Well, it is slightly heavy-handed especially if you wanted to have other colors for your UINavigationBar items, but this is another way you can do it.

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


This will change the background color of every button on the UINavigationBar, as I said, but so far in my testing, I am running into the same problems you are otherwise. With both the properties and the ObjC message methods of changing them aside from changing all of the instances of that class of widget.


Hopefully things are going well for you.


Sincerely,


Doug

Cody Garvin

unread,
May 21, 2012, 12:19:23 PM5/21/12
to pdx-cocoa...@googlegroups.com
Just a thought, 

Which method(s) are you guys running this code in? viewDidLoad:? Try viewDidAppear just to see if it works, then work backwards. I've found some drawing methods don't like to execute until viewWillAppear: or viewDidAppear:

- Cody

Justin R. Miller

unread,
May 21, 2012, 12:30:10 PM5/21/12
to pdx-cocoa...@googlegroups.com
On May 20, 2012, at 5:35 PM, William Frowine, PMP wrote:

> self.navigationController.navigationItem.leftBarButtonItem.tintColor = [UIColor redColor];

FWIW, navigationItem belongs to a given view controller, so you don't need the "navigationController" above. Can't test right now, but maybe that helps?

--

Justin R. Miller
http://codesorcery.net

Northwest Mobile Development LLC

unread,
May 21, 2012, 1:05:57 PM5/21/12
to pdx-cocoa...@googlegroups.com
Thanks all. I was able to use the code from Doug in the ViewDidLoad method and it works just fine.

Thanks so much!

Doug Mason

unread,
May 21, 2012, 1:50:31 PM5/21/12
to pdx-cocoa...@googlegroups.com
Just because it was bothering me a bit, I did some research to check out how to get just the back color.. and I actually found it.
So if you create a new instance of UIBarButtonItem, 

UIBarButtonItem *back = [[UIBarButtonItem alloc] init ];

Then set its tint Color:

[back setTintColor:[UIColor redColor]];

and then assign that button as the NavigationController's back button:

[[self navigationItem] setBackBarButtonItem:back];


It will work as you would anticipate, without having to change the appearance proxy for all UIBarButtonItems within the application in the process. 

William Frowine, PMP

unread,
May 21, 2012, 1:51:35 PM5/21/12
to pdx-cocoa...@googlegroups.com
Thanks Doug!
Reply all
Reply to author
Forward
0 new messages