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
Callum McCurrach
3,150 PointsCode Challenge - Styling Navigation Bar (Message App)
Afternoon,
I've finished the project but for some reason the code challenge for "Styling the navigation bar" keeps failing .. the question is:
- Using the UINavigationBar's appearance proxy, set the background color of the navigation bars to [UIColor redColor].
So, I type out:
[[UINavigationBar appearance] setBackgroundColor:[UIColor redColor]];
What am I missing? I've tried this in Xcode and the compiler there throws no errors, yet the Treehouse one mentions:
instance method '-setBackgroundColor:' not found (return type defaults to 'id') [[UINavigationBar appearance] setBackgroundColor:[UIColor redColor]]; ^~~~~~~~~~~~~~~~~~ 1 error generated.
I've even run the code on the simulator and it actually works - it changes to the 50% red or whatever the Alpha level comes out at.
Perhaps you can help Ben Jakuben ?
5 Answers
james white
78,399 PointsNo where in this thread does it make clear exactly how you are supposed to use setBarTintColor:
#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]];
return YES;
}
@end
...hopefully this helps. And here's the link to the challenge: http://teamtreehouse.com/library/styling-the-navigation-bar
Oh, and in this thread: https://teamtreehouse.com/forum/implementing-designs-for-iphone-styling-the-navigation-bar
Ben says: ..In the Challenge I wanted to use setBarTintColor (which is what it's checking for), but I should have made that clear..
It still was not clear to me since the Challenge still does even mention 'setBarTintColor'
"Challenge Task 1 of 3
Using the UINavigationBar's appearance proxy, set the background color of the navigation bars to [UIColor redColor]."
I didn't know to use setBarTintColor until I read through these forum threads..
............................
For the other parts of the challenge I found these threads helpful:
https://teamtreehouse.com/forum/styling-the-navigation-bar-code-challenge-2-of-3
https://teamtreehouse.com/forum/another-tricky-onechanging-button-color-in-navigation-bar-2
Drat!
I was going add anything further to this posting, but I continuing on to the next challenge...
This stupid 'setBarTintColor' thing comes up again in the 2nd part of the subsequent challenge: http://teamtreehouse.com/library/styling-the-tab-bar
Challenge Task 2 of 2
In the video we changed the color of the tab bar using a background image in interface builder. But we can also change it in code using the same 'setBarTintColor' method we are using for the navigation bar. Pass that message to the UITabBar appearance proxy and set the color to [UIColor blackColor].
Well, kudos to Ben for at least mentioned 'setBarTintColor' in the challenge question, so you may be tempted to recycle the same line of code and just change the color.
Wrong!
Yes, it's just annoyingly enough different that you need to take note:
#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];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
// Customize the tab bar
NSDictionary *titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor, nil];
[[UITabBarItem appearance] setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal];
[[UITabBar appearance] setBarTintColor:[UIColor blackColor]];
return YES;
}
@end
Did you notice it's '[[UITabBar appearance] ', not ' [[UITabBarItem appearance]'
for the last line containing '[UIColor blackColor]'?
John W
21,558 PointsInstead of setting background color, you do setTintColor when using UIAppearance proxy.
Callum McCurrach
3,150 PointsAh okay I'll try that next. Out of curiosity, whats the difference? As setBackgroundColor actually worked..!
EDIT: setTintColor doesn't work; "Bummer! Make sure you are calling the correct method!"
Callum McCurrach
3,150 PointsFYI Just figured it out, its looking for setBarTintColor not setBackgroundColor or setTintColor.
Ben Jakuben
Treehouse TeacherI can see how this is confusing--I'll fix it. The Code Challenge is looking for a solid background color, hence the requirement of setBarTintColor. The error about setBackgroundColor is because of how the code challenge engine is looking for setTintColor, but I can remedy that as well!
Magnus Braathen
7,726 PointsDid you remember to push/make the changes? Because I ran into the same issues with using ยจ
[[UINavigationBar appearance] setBackgroundColor:[UIColor redColor]];
and
[[UINavigationBar appearance] setTintColor:[UIColor redColor]];
which didn't produce any compiler errors in xcode.