首页 > 解决方案 > How can I get the contents of the text box below and display the retrieved text on the label when I press the button?

问题描述

enter image description here

Please tell me what kind of code to write

标签: swift

解决方案


我想您已经将文本框的引用创建为TextView. 现在您需要IBOutlet为标签创建一个新标签。获得对标签的引用后,您可以从 textview 获取文本值并将其显示在标签中。

@IBAction func display(_sender) {
    self.labelView.text = self.TextView.text
    //if you want to clear the textview
    self.TextView.text = ""
}

推荐阅读