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 Improving Our User Interface Adding a Pop of Color

Fernando Lanes
Fernando Lanes
1,137 Points

The button "Show Another Fun Fact" is not changing the color!

@IBAction func showFunFact() {

    let randomColor = colorWheel.randomColor()
    // This calls a random color and then sets it to the variable randomColor

    view.backgroundColor = randomColor

    funFactButton.tintColor = randomColor
    // This now sets both of the above color aspects to the color generated through 'randomColor'.

    funFactLabel.text = factBook.randomFact()
Ian Rushton
Ian Rushton
15,789 Points

Hey, good to see you again! :)

I think the problem you have is within the showFunFact() method that you're calling.

Looks like it's just where you have placed the '=' assignment operator.

Firstly, to make your code more concise and to get the text to match the background colour, try assigning the random colour method to a variable called randomColor, then assign that to 'view.backgroundColor' and 'funFactButton.tintColor', as below.

@IBAction func showFunFact() {

var randomColor = colorWheel.randomColor()
// This calls a random color and then sets it to the variable randomColor

view.backgroundColor = randomColor

funFactButton.tintColor = randomColor
// This now sets both of the above color aspects to the color generated through 'randomColor'.

funFactLabel.text = factBook.randomFact()

}

Hope this helps!!

You may have to delete my comments for this to work.

1 Answer

Fernando Lanes
Fernando Lanes
1,137 Points

I understood what you said and wrote this code below. but it has not worked. I do not know what happens to this application : /