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

Christina Keavaney
Christina Keavaney
424 Points

could not get the button text color to change, would stay the same default (teal) color each time i pressed the button.

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];

self.randomColor = [self.colorWheel randomColor];
self.view.backgroundColor = self.randomColor;
self.funFactLabel.text = [self.factBook randomFact];
[self.funFactButton setTitleColor:self.randomColor forState:0];

}

  • (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];

self.randomColor = [self.colorWheel randomColor];
self.view.backgroundColor = self.randomColor;
self.funFactLabel.text = [self.factBook randomFact];
[self.funFactButton setTitleColor:self.randomColor forState:0];

}

@end

Dr.P reon
Dr.P reon
8,562 Points

Hello there,

Did you try... self.funFactButton.tintColor = randomColor;

2 Answers

just moving this down as the answer from 2 months ago, it was entered as a comment instead:

Dr.P reon 2,678 2mo ago Hello there,

Did you try... self.funFactButton.tintColor = randomColor;

Daniel Mendez
Daniel Mendez
6,296 Points

This is what I did to change the title color:

[self.buttonLabel setTitleColor:self.randomColor forState:UIControlStateNormal];

View the stack overflow post for more info: http://stackoverflow.com/questions/2474289/how-can-i-change-uibutton-title-color