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 Swift 2.0 Improving Our User Interface Random Colors

Kjetil Korsveien
Kjetil Korsveien
1,713 Points

I dont get the button text to switch color

@IBAction func showFunFacts() { let randomColor = ColorModel().getRandomColor() view.backgroundColor = randomColor funFactButton.tintColor = randomColor funFactsLabel.text = factModel.getRandomFact()

5 Answers

Ivan Kazakov
PLUS
Ivan Kazakov
Courses Plus Student 43,317 Points

Hi, Kjetil. I've tested your code - and it works just fine.

Your code doesn't contain a closing curly brace - probably you posted not the whole body of the function and you are setting .tintColor somewhere later to a fixed color?

Tony Teixeira
Tony Teixeira
14,823 Points

.tintColor did not work for me either but .setTitleColor did.

    @IBAction func loadFact() {
        let randomColor = colorModel.getRandomColor()
        view.backgroundColor = randomColor
        funFactButton.setTitleColor(randomColor, forState: .Normal)
        funFact.text = factModel.getRandomFact()
    }
Daren Davis
Daren Davis
6,929 Points

button color doesn't change for me either. (Using Xcode 8.0)