您的位置:首页 > 移动开发 > Swift

Swift UILabel常用功能

2016-06-06 14:32 288 查看
添加UILabel

let label=<span style="background-color: rgb(160, 255, 255);">UILabel</span>(frame: CGRectMake(30, 120, 300, 36))
label.text="测试<span style="background-color: rgb(255, 102, 255);">Swift UILabel</span>"
self.view .addSubview(label)

//<a target=_blank name="baidusnap0" style="color: rgb(255, 153, 0);"></a><span style="background-color: rgb(255, 255, 102);">设置</span>背景色
label.backgroundColor=UIColor.greenColor()

//<span style="background-color: rgb(255, 255, 102);">设置</span>文字颜色
label.textColor=UIColor.redColor()


测试文字居中

let label1=<span style="background-color: rgb(160, 255, 255);">UILabel</span>(frame: CGRectMake(30, 170, 300, 36))
let label2=<span style="background-color: rgb(160, 255, 255);">UILabel</span>(frame: CGRectMake(30, 220, 300, 36))
let label3=<span style="background-color: rgb(160, 255, 255);">UILabel</span>(frame: CGRectMake(30, 270, 300, 36))
label1.text="测试<span style="background-color: rgb(255, 102, 255);">Swift UILabel</span>1"
label2.text="测试<span style="background-color: rgb(255, 102, 255);">Swift UILabel</span>2"
label3.text="测试<span style="background-color: rgb(255, 102, 255);">Swift UILabel</span>3"
label1.backgroundColor=UIColor.grayColor()
label2.backgroundColor=UIColor.grayColor()
label3.backgroundColor=UIColor.grayColor()
self.view.addSubview(label1)
self.view.addSubview(label2)
self.view.addSubview(label3)
//NSTextAlignment 是一个枚举,<span style="background-color: rgb(160, 255, 255);">uilabel</span>默认文字是居左的
label1.textAlignment=NSTextAlignment.Left
label2.textAlignment=NSTextAlignment.Center
label3.textAlignment=NSTextAlignment.Right

效果如下

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: