標籤:標籤 ble 字元 dispose val round name over extc
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 標籤
let label: UILabel = UILabel(frame: CGRect(x: 100, y: 250, width: 200, height: 100))
label.text = "Hello world!"
self.view.addSubview(label)
label.textAlignment = .center
// 設定文本高亮
label.isHighlighted = true
// 設定文本醒目提示
label.highlightedTextColor = UIColor.black
// 富文本設定
let attributeString = NSMutableAttributedString(string:"welcome to china")
// 改變指定位置的字串的文字 font
attributeString.addAttribute(NSFontAttributeName,
value: UIFont.systemFont(ofSize: 20),
range: NSMakeRange(0, 4))
// 設定指定位置的字型顏色
attributeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.blue,
range: NSMakeRange(0, 3))
// 設定指定位置的文字背景顏色
attributeString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.green,
range: NSMakeRange(3,3))
label.attributedText = attributeString
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
swift 實踐- 03 -- UILabel