UI控件之UILabel

来源:互联网 发布:win10 办公软件 编辑:程序博客网 时间:2024/06/04 23:33

//  Created by Catherine on 2017/8/28.

//  Copyright © 2017 Catherine. All rights reserved.

//


import UIKit


class ViewController: UIViewController {


    overridefunc viewDidLoad() {

        super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.

        let label :UILabel = UILabel(frame: CGRect(x:120, y: 100, width:200, height: 300))

        //设置label上的文字

        label.text = "I am a label"

        //设置字体

        label.font = UIFont.boldSystemFont(ofSize: 19)

        //设置字体的颜色

        label.textColor = UIColor.blue

        //label.textColor = UIColor(colorLiteralRed: <#T##Float#>, green: <#T##Float#>, blue: <#T##Float#>, alpha: <#T##Float#>)

        //alpha是透明度

        //设置label的背景颜色

        label.backgroundColor = UIColor.magenta

        //设置文字的对齐方式

        label.textAlignment = NSTextAlignment.center

        //设置label的阴影

        label.shadowColor = UIColor.orange

        //设置阴影的偏移范围  (width向右偏移 height向下移动)

        label.shadowOffset = CGSize(width: 30, height:10)

        //设置label的行数   =0是无限行展示

        label.numberOfLines = 2

        self.view.addSubview(label)

        

        

    }


    overridefunc didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }


       

}


原创粉丝点击