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
Tristan Gaebler
6,204 PointsCan someone help me with the extra credit?
I am stuck on the extra credit for the second stage of how to make an iPhone app in iOS 7. The goal is change to the label color when I press the button. How would I do that? Thanks
6 Answers
Michael Hulet
47,913 PointsIt's actually pretty simple. All you have to do is add 1 line of code inside the buttonPressed method in THViewController.m. The solution looks like this (with the full method):
- (IBAction)buttonPressed {
self.predictionLabel.text = @"YES";
self.predictionLabel.textColor = [UIColor redColor];
}
What you're doing is setting the textColor property of the UILabel called predictionLabel (which is a property of self) to the red that is returned by the redColor class method of UIColor. You call all those properties with the usual dot notation, and you set them equal to red using UIColor. This is how you change the color of most (if not, all) things in Objective-C on the iPhone. You can read all about the magic of UIColor in Apple's Documentation for the UIColor Class
Stone Preston
42,016 Pointsyou can set the text color of the label using
self.predictionLabel.textColor = ...
ill leave the right side of the assignment for you to figure out. check out the UIColor documentation for more info on using colors in your app
Stone Preston
42,016 Pointsyou have an array of predictions, and a method that randomly selects one of those predictions from that array. you need to add an array of UIColor objects, and a method that randomly selects one of those colors and returns it. then whenever a prediction is made, you need to change the text color of the predictionLabel using the return value of your randomColor method.
can you post some code you have tried so far?
Tristan Gaebler
6,204 PointsIm not that far up in the course. I jus need to make the label red when pressed
Tristan Gaebler
6,204 PointsThese are the instructions... Change the color of the predictionLabel text to red when the buttonPressed method is called.
Tristan Gaebler
6,204 PointsThanks for the help guys!!!