标签:
@IBAction func buttonClick_LabelCtrl(sender: AnyObject) {
//定义CGRect来初始化UILable
var frame: CGRect = CGRect(x: 50, y: 50, width: 200, height: 200)
var label: UILabel = UILabel(frame: frame)
//获取和设置字体大小自适应属性(可以通过UIFont来设置字体)
var adjuststate: Bool = label.adjustsFontSizeToFitWidth
label.adjustsFontSizeToFitWidth = false
//设置显示行数,如果设置为0,表示无限制(此时要注意创建UILabel是用的CGrect的大小)
label.numberOfLines = 0
//给Label赋值
label.text = "I am a dynamic label, this is a long string to test number of lines of label "+String(stringInterpolationSegment: adjuststate)
//设置字体颜色
label.textColor = UIColor.redColor()
//是否高亮
label.highlighted = true
//是否有文字阴影
label.shadowColor = UIColor.greenColor()
self.view.addSubview(label)
}
标签:
原文地址:http://www.cnblogs.com/AlwinXu/p/4457345.html