打印到标签(Swift 2) [英] Printing to a label (Swift 2)

查看:53
本文介绍了打印到标签(Swift 2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在控制台上打印了一些文字。但我希望将文本打印到viewcontroller上的标签上。我只有一些简单的代码print(ab)。我应该如何打印到标签?

I have some text printing to the console. But I want the text to be printed to a label on the viewcontroller. I just have some simple code "print(ab)". How should i get it to print to the label?

推荐答案


在ViewController上创建新标签故事板和正确的对齐/大小,以便正确显示,并能够显示具有适当长度的全文消息,按ctrl并将该行拖动到视图控制器。然后它弹出一个框并将其标记为动作并给出一个该标签的名称为yourMessageLabel

Create new Label on your ViewController with storyboard and Proper alignment/size so it is visible properly and can able to show full text message with proper length, press ctrl and drag it that line to the view controller.Then it pops up a box and mark it as a action and give a name to that Label "yourMessageLabel"

然后它会自动创建代码,如

Then it automatically create code like

 @IBOutlet weak var yourMessageLabel: UILabel!
var yourMessageText = "Message to be display on Console and View"

override func viewDidLoad(){
   super.viewDidLoad()

 // do other stuff

 // assign message text to Label to be display on your View

 self.yourMessageLabel.text = (self.yourMessageText as? String)

// print message on console

 print(self.yourMessageText)

}

这篇关于打印到标签(Swift 2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆