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 Simple iPhone App with Objective-C Improving Our User Interface Using the ColorWheel Class

Same Button Text Color problem...

I'm having same issue with button text color refusing to change last the first poster for this video. My code is exactly the same as the video AND exactly the same as the code cut in at the first question.

One of the answers given, re-drag the button to make the UIOutlet over again was the first thing I tried. I have done it twice to no avail. There was a suggestion to 'change to default'. Not sure what that is, but if it is to make sure the button's color is set to 'default' in the Attributes Inspector, I've done that as well.

The code to change the background color is the same as that used to change the button color (apart from the specific object referenced obviously) and the background IS working correctly. So I am completely at a loss. This looks like a perfect thing for the following debugging videos to help me with, but this problem is not causing the app to crash. It is simply a small aesthetic failure, nonetheless driving me nuts!

5 Answers

Chris Reilly
Chris Reilly
12,086 Points

Hi Erick,

Not sure if you're still experiencing this problem since you last posted here 11 months ago, but just in case you or anyone else is experiencing this problem (as I was just now), what I had to do to fix it was:

  1. Go to Main.storyboard
  2. Select the button
  3. In the Attributes inspector, under the View section, set the Tint to "Default." Mine was set to the same color as the starting background color.

Anyway, not sure if anyone else has the issue, but this is what turned out to solve the issue for me!

Chris

Christian A. Castro
Christian A. Castro
30,501 Points

Chris Reilly thank you!! I was experiencing the same problem even knowing everything was okay. It was just to set "Tint" to Default. Thank you so much.

Thanks for the answer. That's a great life saver! I had the same problem with mine as well. Changing the tint property to Default really solved the problem.

Damien Watson
Damien Watson
27,419 Points

Hey Erick, Assuming that the button is correctly attached to the ViewController, it may be the way you are setting the color. Can you show us that code?

You have to use the 'setTitleColor:forState:' method, this also gives you better control over each state.

// Won't work
myButton.titleLabel.textColor = [UIColor redColor];

// Will colorize
[myButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

ViewController.h

import <UIKit/UIKit.h>

@class FactBook; @class ColorWheel;

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UILabel *funFactLabel; @property (strong, nonatomic) FactBook *factBook; @property (strong, nonatomic) ColorWheel *colorWheel; @property (weak, nonatomic) IBOutlet UIButton *FunFactButton;

@end

ViewController.m#import "ViewController.h"

import "FactBook.h"

import "ColorWheel.h"

@interface ViewController ()

@end

@implementation ViewController

  • (void)viewDidLoad { [super viewDidLoad];

    self.factBook =[[FactBook alloc] init]; self.colorWheel =[[ColorWheel alloc] init];

    UIColor *randomColor = [self.colorWheel randomColor]; self.view.backgroundColor = randomColor; self.FunFactButton.tintColor = randomColor; self.funFactLabel.text = [self.factBook randomFact]; }

  • (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }

  • (IBAction)showFunFact { UIColor *randomColor = [self.colorWheel randomColor]; self.view.backgroundColor = randomColor; self.FunFactButton.tintColor = randomColor; self.funFactLabel.text = [self.factBook randomFact];

}

@end

Sorry. Here.

ViewController.h

#import <UIKit/UIKit.h>


@class FactBook;
@class ColorWheel;

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UILabel *funFactLabel;
@property (strong, nonatomic) FactBook *factBook;
@property (strong, nonatomic) ColorWheel *colorWheel;
@property (weak, nonatomic) IBOutlet UIButton *FunFactButton;

@end

ViewController.m

#import "ViewController.h"
#import "FactBook.h"
#import "ColorWheel.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.factBook =[[FactBook alloc] init];
    self.colorWheel =[[ColorWheel alloc] init];

    UIColor *randomColor = [self.colorWheel randomColor];
    self.view.backgroundColor = randomColor;
    self.FunFactButton.tintColor = randomColor;
    self.funFactLabel.text = [self.factBook randomFact];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)showFunFact {
    UIColor *randomColor = [self.colorWheel randomColor];
    self.view.backgroundColor = randomColor;
    self.FunFactButton.tintColor = randomColor;
    self.funFactLabel.text = [self.factBook randomFact];

}

@end

I'm kinda hoping the answer can be 'here's where you went wrong in your code', or 'new version of Xcode means this has to be changed'. If there are chunks of code that literally have to be added to this to make it work then the lesson is wrong. Seems to me the lesson must work as written and I am missing something otherwise every person taking this would have it fail. And the instructor's example does work as he runs it in the video.

Damien Watson
Damien Watson
27,419 Points

Haha, I wish it was something like that as well :)

Try my suggestion below, your code works fine, so it has to be the connection somehow.

Damien Watson
Damien Watson
27,419 Points

I have pasted your code in and it works fine. If you paste the below line in after all the others in 'viewDidLoad' it will definitely show whether or not the button is connected:

self.FunFactButton.backgroundColor = [UIColor redColor];

The only other thing I can suggest (and I know you've redone these connections) is go to the storyboard and right click on the button. The button should have:

  • 'Touch Up Inside' linked to View Controller - showFunFact
  • Referencing Outlets 'FunFactButton' - View Controller