[英]Swift: How can I declare a statement based off the title of a button?
I have a button that's title is set to "calculator" When this button in my view controller is tapped, it hides and shows a bunch of objects and it changes to the title of the button to "back": 我有一个标题设置为“计算器”的按钮,当点击我的视图控制器中的此按钮时,它隐藏并显示了一堆对象,并将其标题更改为“后退”:
@IBAction func calculatorButtonTapped(sender: AnyObject) {
calculatorContainer.hidden = false
inspirationLabel.hidden = true
beginningLabel.hidden = true
menuExampleButton.hidden = true
aboutButton.hidden = true
calculatorButton.setTitle("Back", forState: UIControlState.Normal)
}
When the title is set to "back", and when that button is clicked, I want everything that was hidden to be shown and everything that was shown to be hidden. 当标题设置为“后退”时,并且单击该按钮时,我希望显示所有隐藏的内容以及显示的所有内容。 When the title is set to "calculator", I want everything from the above code to occur.
当标题设置为“计算器”时,我希望上述代码中的所有内容都可以发生。 How can I do this?
我怎样才能做到这一点?
You can try this code: 您可以尝试以下代码:
@IBAction func calculatorButtonTapped(sender: AnyObject) {
calculatorContainer.hidden = !calculatorContainer.hidden
inspirationLabel.hidden = !inspirationLabel.hidden
beginningLabel.hidden = !beginningLabel.hidden
menuExampleButton.hidden = !menuExampleButton.hidden
aboutButton.hidden = !aboutButton.hidden
calculatorButton.setTitle("Back", forState: UIControlState.Normal)
if !calculatorContainer.hidden{
inspirationLabel.hidden = true
beginningLabel.hidden = true
menuExampleButton.hidden = true
aboutButton.hidden = true
}
}
This will switch back and forth between hidden and not hiding your image. 这将在隐藏和不隐藏图像之间来回切换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.