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
haydensteed
1,328 PointsHow do you make a button do something
how do you code something like if button pressed{ points = points + 1
}
3 Answers
kjvswift93
13,515 PointsFirst, you need to connect the button from main.storyboard with it's respective swift file as an @IBAction.
kjvswift93
13,515 PointsFirst, you need to connect the button from main.storyboard with it's respective swift file as an @IBAction.
Meek D
3,457 PointsBasically this code below we are using a UILabel and UIButton , the goal is that when the button is pressed we want to display hello into the UILabel
@IBOutlet weak var displaylabel :UILabel!
@IBAction func DoSomething(sender :UIButton) {
displaylabel.text = " Hello "
}