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 Build a Playlist Browser with Objective-C Working With Multiple View Controllers UIButton Recap

Devin Scheu
Devin Scheu
66,191 Points

Help With IOS

Question: Before we finish let’s also programmatically change the tint color of our button to something more appealing. I’ve set up a UIColor object for you to use and like last time, I want you to use the documentation or the Internet to figure out which method to use. Assign the redColor UIColor object to the tint property of the timerButton.

Code:

ViewController.h
#import "UIViewController.h"
#import "UIButton.h"

@interface ViewController : UIViewController

@property (strong, nonatomic) IBOutlet UIButton *timerButton;

@end
ViewController.m
#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.timerButton setTitle:@"Start!" forState:UIControlStateNormal];

    UIColor *redColor = setTintColor[UIColor redColor];

    // Enter your code below!

}


@end

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Devin,

You've gone somewhat off the path for task 2 whereas in task 1 it appears you had some sort of idea what was going on, if that's the case I highly recommend you go back and re-watch the previous video as methods are declared the same way regardless of whether it's setTintColor or setTitle.

Moving on, for this challenge you simply need to call setTintColor on self.timerButton and set it's value to the UIColor instance of redColor.

[self.timerButton setTintColor:[UIColor redColor]];

Happy coding!

Michael Hulet
Michael Hulet
47,913 Points

In my opinion, using dot notation looks a little cleaner. Using dot notation, it'd look like this:

self.timerButton.tintColor = [UIColor redColor];

It's totally a preference thing, but I like to access all properties with dot notation and all methods with square bracket notation, just to be super clear

David Rynn
David Rynn
10,554 Points

My understanding is that dot notation is preferred in the industry right now but what do I know.

Also, since this was already declared above where we are supposed to input our code:

UIColor *redcolor = [UIColor redColor];

You only need to write:

self.timerButton.tintColor = redColor;

adding [UIColor redColor]; is redundant and defeats the purpose of the variable.