Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

[SOLVED] Another tricky one...changing button color in navigation bar

I am referring to this code challenge :http://teamtreehouse.com/library/styling-the-navigation-bar Here's the question : Now we want to change the color of the text of our navigation bar buttons to white. Use the appearance proxy to change the color using [UIColor whiteColor].

And now my code which needs to be debugged :

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Customize the nav bar
    UIImage *backgroundImage = [UIImage imageNamed:@"navBarBackground"];
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
   [[UINavigationBar appearance] setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBarButtonItemColor:[UIColor whiteColor]];


    return YES;
}

@end

2 Answers

Thomas Nilsen
Thomas Nilsen
14,957 Points

try something like this:

        [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
    [[UINavigationBar appearance] setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

EDIT As far as I can tell, the code I wrote is the same as you already have - but I took all 3 challenges now without problems

EDIT 2 It was very close but not entirely. Your last line ;)

Thanks ! I guess i tried something too complicated for the last question...I can't believe it was that easy ! Very subtle question !