加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift UILabel常用功能

发布时间:2020-12-14 06:55:44 所属栏目:百科 来源:网络整理
导读:添加 UILabel let label=span style="background-color: rgb(160,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=_

添加UILabel

let label=<span style="background-color: rgb(160,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,102);">设置</span>背景色
        label.backgroundColor=UIColor.greenColor()
        
        //<span style="background-color: rgb(255,102);">设置</span>文字颜色
        label.textColor=UIColor.redColor()


测试文字居中


        let label1=<span style="background-color: rgb(160,170,36))
        let label2=<span style="background-color: rgb(160,220,36))
        let label3=<span style="background-color: rgb(160,270,36))
        label1.text="测试<span style="background-color: rgb(255,255);">Swift UILabel</span>1"
        label2.text="测试<span style="background-color: rgb(255,255);">Swift UILabel</span>2"
        label3.text="测试<span style="background-color: rgb(255,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);">uilabel</span>默认文字是居左的
        label1.textAlignment=NSTextAlignment.Left
        label2.textAlignment=NSTextAlignment.Center
        label3.textAlignment=NSTextAlignment.Right

效果如下


(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读