首先 给需要创建的label 设置frame
let textLabel = UILabel(frame:CGRectMake(self.view.frame.size.width/8,20,self.view.frame.size.width*3/4,100))
给label 设值
textLabel.text = “现在我们来开始学习如何创建我们的第一个swift控件吧 -UILabel”
设置是否默认换行
textLabel.numberOfLines = 0
设置label的背景颜色
var whitColor = UIColor(red:1.0,green:1.0,blue:1.0,alpha:1.0)
textLabel.backgroundColor = whitColor
设置label的文本信息展示样式,
textLabel.textAlignment = NSTextAlignment.Left
设置label的字体
var textFont = UIFont(name: nil, size : 11)
textLabel.font = textFont
设置label的文本颜色
var greenColor = UIColor(red:0.9,green:0.2,blue:0.6,alpha:1.0)
textLabel.textColor = greenColor
添加视图到view
self.view.addSubview(textLabel)