//? ? ? ? 定義局部label控件,設置label標簽x坐標:10,y坐標:20,長:300,寬:100
let lable = UILabel(frame:CGRectMake(10,20,view.frame.size.width-20,100))
//? ? ? ? 設置文字屬性
lable.text = "我是label,我的屬性有很多,你都試一下,看我的強大!!!設置對其方式的設置 Left,Center,Right"
//? ? ? ? 設置控件背景顏色
lable.backgroundColor = UIColor.brownColor()
//? ? ? ? 設置文字顏色
lable.textColor = UIColor.whiteColor()
//? ? ? ? 設置對其方式的設置 Left,Center,Right
lable.textAlignment = NSTextAlignment.Left //文字右對齊
//? ? ? ? 文字陰影的設置, 灰色陰影
lable.shadowColor = UIColor.greenColor()
//? ? ? ? 陰影的偏移量
lable.shadowOffset = CGSizeMake(-1, 1)
//? ? ? ? 字體的設置
//? ? ? ? lable.font = UIFont(name: "Zapfino",size: 15)
//隱藏尾部并顯示省略號
//? ? ? ? lable.lineBreakMode = NSLineBreakMode.ByTruncatingTail
//隱藏中間部分并顯示省略號
//? ? ? ? lable.lineBreakMode = NSLineBreakMode.ByTruncatingMiddle
//隱藏頭部并顯示省略號
//? ? ? ? lable.lineBreakMode = NSLineBreakMode.ByTruncatingHead
//? ? ? ? lable.lineBreakMode = NSLineBreakMode.ByClipping
//? ? ? ? 文字大小自適應標簽寬度,當文字超出標簽寬度時,自動調整文字大小,使其不被截斷
// lable.adjustsFontSizeToFitWidth = true
//? ? ? ? 使標簽可以顯示多行文字,0是多行顯示,設置2最多顯示2行
lable.numberOfLines = 2
//? ? ? ? 設置文本高亮
lable.highlighted = true
//? ? ? ? 設置文本高亮顏色
lable.highlightedTextColor = UIColor.redColor()
//? ? ? ? 富文本設置
let attributeString = NSMutableAttributedString(string:" welcome to hangge.com")
//? ? ? ? 從文本0開始6個字符字體HelveticaNeue-Bold,16號
attributeString.addAttribute(NSFontAttributeName, value: UIFont(name: "HelveticaNeue-Bold",size: 16)!, range: NSMakeRange(0, 6))
//? ? ? ? 設置字體顏色
attributeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.blueColor(), range: NSMakeRange(0, 3))
//? ? ? ? 設置字體背景顏色
attributeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.greenColor(), range: NSMakeRange(3, 3))
lable.attributedText = attributeString
self.view.addSubview(lable)