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 trialMatthias Seeber
14,167 PointssetTitle Method Button
Can anybody help me with this method? whats wrong with it?
class ViewController: UIViewController {
@IBOutlet weak var timerButton: UIButton!
var redColor: UIColor = UIColor.redColor()
override func viewDidLoad() {
super.viewDidLoad()
//Add your code below
func setTitle(_ title: "Start"?, forState state: timerButton)
}
}
2 Answers
Dominic Bryan
14,452 PointsI am assuming you need to set the title of the button to "Start",
timerButton.setTitle("Start", forState: .Normal)
Thank you Steve Hunter who posted this response on another post a few hours back
Dom
Matthias Seeber
14,167 PointsThanks a lot, it was very helpful. Awesome :D
Matthias Seeber
14,167 PointsMatthias Seeber
14,167 Pointsoh i see what does the ".Normal" mean?
Dominic Bryan
14,452 PointsDominic Bryan
14,452 PointsMatthias Seeber .Normal refers to the state in which the button is to set the title, so in this instance when the button is normal (i.e nothing going on) the title is "Start".
You can choose to set titles for different states, so .Highlighted for example. If you do not specify any other state the button will always use the .Normal state title as its default title no matter what, if its highlighted, selected or what ever.
Take a look at UIButton class reference setTitle(_:forState:) in apple docs: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIButton_Class/index.html#//apple_ref/occ/instm/UIButton/setTitle:forState:
and UIControlState at: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIControl_Class/index.html#//apple_ref/c/tdef/UIControlState
Just taking a brief look will give you an idea of what the state may be used for in another case (this is funny because the ControlStates are stored in a Enum.... case..... bad joke but hey ho).
Hope this helps Thanks Dom