我有一个按钮,按下时会更改 TextView ,我希望它在再次按下按钮时将更改后的文本切换到原始文本。
我的代码:
//An IBOutlet for the textview
@IBOutlet weak var changingText: UITextView!
//The button that changed the text
@IBAction func viewChangedText(sender: AnyObject) {
changingText.text = "Changed Text"
}
现在我希望再次按下按钮时文本会变回来。
注意:如果可能的话,原文位于 Storyboard中。您能否帮我在原始文本存在时将按钮的文本更改为“查看”,并在更改后的文本存在时将按钮的文本更改为“隐藏”。
最佳答案
var didChange = false
@IBOutlet weak var changingText: UITextView!
//The button that changed the text
@IBAction func viewChangedText(sender: AnyObject) {
didChange = !didChange
if didChange {
changingText.text = "Changed Text"
}else{
changingText.text = "Original text"
}
}
关于ios - 如何在 Swift 中使用函数更改标签后将其更改为原始文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32415461/