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

Joel Birlingmair
Joel Birlingmair
3,130 Points

funFactButton.tintColor will not change

For the life of me I cannot seem to change the color of the UIButton text after pressing the button. The view.backgroundColor changes just fine, but the button never does. It just stays light blue all the time. Please help!

Here is what I have for showFunFact()

@IBAction func showFunFact() {
        var theColor = colorWheel.randomColor()
        funFactButton.tintColor = theColor
        view.backgroundColor = theColor


        funFactLabel.text = factList.randomFact()    }
}

7 Answers

Joel Birlingmair
Joel Birlingmair
3,130 Points

AH! I just figured it out. Here is what it was:

On the attributes inspector for the main.storyboard for the funButtonLabel I had manually changed the "text color" to match the color I wanted it to be when the app launches. (my background color isn't exactly blue at launch like yours, I just picked a color off the color wheel that I liked which was more teal-ish and I used the dropper to make the text match the background at launch)

My bad! I guess with the text color of the font changed, no matter what the tint, it couldn't show anything other than the "text color". I still don't fully understand the difference between the "tint color" and the "text color". I read about them a little in the Documentation though. It seems some items in the view inherit "tint color" from the parent view. So "tint color" is the same thing as "text color" when they are set to default but not otherwise?

Switching the "text color" back to "default" fixed the problem for me.

Thanks again for walking me through all this.

I was having the exact same problem! Thanks so much for explaining it.

Mike Atkinson
Mike Atkinson
6,882 Points

Joel Birlingmair , Thanks so much for posting this and finding the problem! I was having the same problem, and setting the text color back to default in the attributes inspector fixed it.

My guess is that the attributes inspector might have permanent priority over some properties?

Pasan Premaratne
STAFF
Pasan Premaratne
Treehouse Teacher

Joel Birlingmair,

Double check your funFactButton outlet and make sure it's connected to the button in Interface Builder. Let me know if that works!

Joel Birlingmair
Joel Birlingmair
3,130 Points

Hey Pasan!

Thanks so much for answering my question!

Yeah, I checked. When I mouse over the little symbol in the left hand pane left of the @IBOutlet declaration, it highlights the funFactButton on the interface builder. Also, it shows a connection on the Reference outlet section of the Connections Inspector.

I noticed in the video that the color of the text in the button does not change after the last modification of your code because in the video you don't ever press the button on the app before moving on to the status bar color modification in the app delegate. Just prior to that in the video you had the tint color of the button randomly changing supposedly (Just not in sync with the background), but you pressed the button twice and it just seemed to change from teal to red-ish. On the second button press it did not seem to change, but that may just be that the purple was so close to the brown that they both looked red-ish to me.

Here is something I have noticed. When I change the "Tint Color" manually in the attributes inspector for the funFactButton, the interface builder does not show any change either. The only way I can get the color of the text to change is by manually changing the "Text Color" in the attributes inspector.

Is there something I am missing here? Could the tintColor be somehow related to a draw function that is already complete or needs to request an update? Or do I need a clear background image or color to allow the tint to pass through? I think my version of Xcode looks a little different than yours, but everything is in about the same place. I am running version: 6.0.1

Pasan Premaratne
STAFF
Pasan Premaratne
Treehouse Teacher

Hey Joel Birlingmair!

Thanks for the detailed response. I ran it on my machine using Xcode 6.0.1, Xcode 6 GM and Xcode 6 Beta 7 (the last two are what I used to record the course) and it works as expected. Recorded a video to show you how it looks on mine. Try cleaning and building again. In the Product menu, select Clean and then Build.

Joel Birlingmair
Joel Birlingmair
3,130 Points

Hi Pasan,

Well, that did not work, but I really appreciate that little video showing how yours works as well as the code next to it.

My gut tells me the problem has to be in the attributes for the storyboard.

I have re-watched a lot of the track to see if my storyboard is set up just like yours, but at this point I have fiddled with so much it could be anything. As far as I can tell we have the same thing set up.

Could you show me what you have in the attributes inspector for the main.storyboard?