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

Gregory Millan
Gregory Millan
3,719 Points

Tint color on the button not coinciding with background color

Here is my code below.

@IBAction func showFunFact() {
    let randomColor = ColorModel().getRandomColor()
    view.backgroundColor = randomColor
    funFactButton.tintColor = randomColor
    funFactLabel.text = factBook.getRandomFact()
}

As you can see from the code above, the background color and tint color are both set to randomColor. However, the tint color is not changing when i runt the app. Everything else happens to fine though.

Timothy Kaye
Timothy Kaye
2,765 Points

Gregory, how did you go with sorting this out?

Can you post your 'ColorModel.swift' file so that we can see if there is a typo?

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Gregory Millan,

Are you trying to change the color of you button to a random color as well? If so, what you need to be setting the random color on is the UIButton's backgroundColor property.

// It would look like this
funFactButton.backgroundColor = randomColor

Hope this is the answer you were looking for.