1_UILabel

//
//  ViewController.swift
//  1_UILabel
//
//  Created by Larry on 2016/12/7.
//  Copyright © 2016年 nfIOS. All rights reserved.


import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let label = UILabel(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
        //設置字體內容
        label.text = "larry111111111111"
        //設置字體顏色
        label.textColor = UIColor.orange
        //設置字體大小
        label.font = UIFont.boldSystemFont(ofSize: 34)
        //設置背景顏色
        label.backgroundColor = UIColor.blue
        //設置對齊方式
        label.textAlignment = .center
        //設置高亮模式(默認爲false)
        label.isHighlighted = true
        //設置高亮模式下的字體顏色
        label.highlightedTextColor = UIColor.brown
        //超出label邊界文字的截取方式
        label.lineBreakMode = .byClipping
        //是否能與用戶交互(默認爲false)
        label.isUserInteractionEnabled = true
        //設置文本文字自適應大小
        label.adjustsFontSizeToFitWidth = true
        //設置自動換行
        label.numberOfLines = 0
        //設置是否可改
        label.isEnabled = false
        //文本陰影顏色
        label.shadowColor = UIColor.darkGray
        //陰影大小
        label.shadowOffset = CGSize(width: 10, height: 10)
        //baselineAdjustment這個值控制文本的基線位置,只有文本行數爲1是有效
        /*
         UIBaselineAdjustmentAlignBaselines = 0,默認,文本最上端與中線對齊。
         UIBaselineAdjustmentAlignCenters,  文本中線與label中線對齊。
         UIBaselineAdjustmentNone, 文本最低端與label中線對齊。
         */
        label.baselineAdjustment = .alignBaselines
        //minimumScaleFactor控制字體大小自適應(默認爲0.0)
        //設置最小收縮比例,若是Label寬度小於文字長度時,文字進行收縮,收縮超過比例後,中止收縮。
        label.minimumScaleFactor = 0.5
        label.adjustsFontForContentSizeCategory = true
        label.allowsDefaultTighteningForTruncation = true
        
        self.view.addSubview(label)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
本站公眾號
   歡迎關注本站公眾號,獲取更多信息