Reputation: 479
The user needs to press a button to show label contents and hide again when the button is released.
With the following, the label is shown when the user press the button but stay shown after the user releases the button.
myLabel.isHidden = true
and
@IBAction func myButton(_ sender: UIButton) {
myLabel.isHidden = false
Any help is more than welcome.
Upvotes: 0
Views: 560
Reputation: 322
You need to create 2 IbActions for the button. When you create theses actions you can change the event. One needs to be Touch Down and one need to be Touch Up Inside.
Once you have the 2 actions you can then simply hide and show the label in each of the actions.
//Touch Down Event added to this action
@IBAction func buttonPressed(_ sender: UIButton) {
print("Button Pressed")
myLabel.isHidden = false
}
//Touch Up Inside Event added to this action
@IBAction func buttonReleased(_ sender: UIButton) {
print("Button Released")
myLabel.isHidden = true
}
Upvotes: 2
Reputation: 374
you need to use the touch down method to hide the label and use touch up inside to show it again.
@IBAction func touchUpInside(_ sender: UIButton) {
print("inside")
label.isHidden = true
}
@IBAction func touchDown(_ sender: Any) {
print("touch down")
label.isHidden = false
}
Upvotes: 2