let label = UILabel(frame: CGRect(x: 10, y: 240, width: 300, height: 35))
? ? ? ? label.backgroundColor = UIColor(displayP3Red: 153.0/255, green: 153.0/255, blue: 153.0/255, alpha: 1) // 設(shè)置背景顏色
? ? ? ? label.text = "hello world" // 設(shè)置文字
? ? ? ? label.textColor = UIColor.white // 設(shè)置文字顏色
? ? ? ? label.numberOfLines = 0 // 設(shè)置文字自動換行
? ? ? ? label.textAlignment = NSTextAlignment.center // 設(shè)置文字居中
? ? ? ? label.font = UIFont.systemFont(ofSize: 11) // 設(shè)置字體大小
? ? ? ? label.layer.cornerRadius = 3 // 設(shè)置圓角
? ? ? ? label.layer.masksToBounds = true
? ? ? ? label.shadowColor = UIColor.red // 陰影顏色
? ? ? ? label.shadowOffset = CGSize(width: 1, height: 1) // 陰影偏移量
? ? ? ? label.layer.borderColor = UIColor.green.cgColor // 邊框顏色
? ? ? ? label.layer.borderWidth = 2 // 邊框?qū)挾?/p>
? ? ? ? self.view.addSubview(label)