1. 程式人生 > >UI控制元件常用設定之直接貼上使用swfit版

UI控制元件常用設定之直接貼上使用swfit版

常用控制元件設定

  1. UILable
  2. UIButton
  3. UITableViewController
  4. 常用巨集設定

UILabel

常見設定:

  1. 設定換行
  2. 設定對齊方式
 lazy private var messageTitleLabel: UILabel = {
    let label = UILabel()
    label.textColor = UIColor.black
    label.backgroundColor = .clear
    label.textAlignment = NSTextAlignmentCenter;
    label.font = UIFont.systemFont(ofSize: 10)
    label.numberOfLines = 0
    return label
}()

UIButton

常見設定:

  1. 設定圓角、邊框樣式
  2. 設定圖片與標題相對位置
    lazy private var button: UIButton = {
        let button = UIButton(type: .custom)
        button.backgroundColor = .clear
        button.setTitle("詳情", for: .normal)
        button.imageEdgeInsets = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 50)
        button.titleEdgeInsets = UIEdgeInsets.init(top: 0, left: -50, bottom: 0, right: 0)
        button.setTitleColor(.orange, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 10)
        
        copyButton.layer.cornerRadius = 10
        copyButton.layer.masksToBounds = true
        copyButton.layer.borderColor = UIColor.orange.cgColor
        copyButton.layer.borderWidth = 1.0
        return button
    }()

UITableViewController

常見設定問題

  1. UITableViewCell重用
  2. 取消分割線,取消點選跳轉
  3. 設定右側細節
  4. 新增分割線,行之間距離(預設沒有方法,新增對應view檢視即可)
	self.selectionStyle = .none
	self.tableView.separatorStyle = .none
	self.tableView.register(WMCommunitySendCodeTableViewCell.self, forCellReuseIdentifier: "cell")

常用巨集設定

  1. 顏色設定
  2. 相對距離設定
func RGB(r: CGFloat, g: CGFloat, b: CGFloat, alpha: CGFloat) -> UIColor {
    return UIColor (red: r/225.0, green: g/225.0, blue: b/225.0, alpha: alpha)
}

func kScale(_ num: CGFloat) -> CGFloat {
    return num * screenWidth / 375
}

生命週期

ios開發生命週期分UIViewController生命週期App的生命週期,掌握的意義在於熟悉程式的執行過程。
生命週期