【Swift】UILabel的簡單操作方法

來源:互聯網
上載者:User

標籤:

@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)

        

    }

【Swift】UILabel的簡單操作方法

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.