//設(shè)置標(biāo)簽x坐標(biāo):10,y坐標(biāo):20,長:300,寬:100
let label=UILabel(frame:CGRectMake(10,20,300,100))
//顯示文本【需要顯示什么就設(shè)置這個text的屬性即可】
label.text="張入銘"
// label的字體顏色
label.textColor=UIColor.redColor()//紅色文字
// label的背景顏色
label.backgroundColor=UIColor.blackColor()//黑色背景
// label的文字對齊方式
label.textAlignment=NSTextAlignment.Right//文字右對齊
//? ? label陰影顏色【要設(shè)置偏移位置】(字體的陰影顏色)
label.shadowColor=UIColor.grayColor()//灰色陰影
//? ? label陰影偏移位置
label.shadowOffset=CGSizeMake(-5,5)//陰影的偏移量
//多行顯示,默認(rèn)是一行的,0表示的多行顯示(與高度有關(guān))Label自適應(yīng)自動換行,顯示兩行文字(默認(rèn)只顯示一行,設(shè)為0表示沒有行數(shù)限制)
label.numberOfLines=0
//設(shè)置label文本高亮
label.highlighted=true
//設(shè)置label文本高亮顏色
label.highlightedTextColor=UIColor.greenColor()
//? ? label圓角屬性
label.layer.masksToBounds=true;
//? ? label圓角半徑
label.layer.cornerRadius=10;
//? ? label圓角邊框顏色
label.layer.borderColor=UIColor.blueColor().CGColor;
//? ? label圓角邊框?qū)挾?/b>
label.layer.borderWidth=1;
//? label的字體大小
/**
systemFontOfSize(20) -> UIFont ? ? ? ? (文字大小)
boldSystemFontOfSize(20) -> UIFont ? ? (加粗類型)
italicSystemFontOfSize(20) -> UIFont? ? (斜體類型)
*/
label.font=UIFont.systemFontOfSize(50)
//設(shè)置字體時,同時設(shè)置大小
label.font=UIFont(name:"您好!", size:50)
//隱藏尾部并顯示省略號
label.lineBreakMode=NSLineBreakMode.ByTruncatingTail
//隱藏中間部分并顯示省略號
label.lineBreakMode=NSLineBreakMode.ByTruncatingMiddle
//隱藏頭部并顯示省略號
label.lineBreakMode=NSLineBreakMode.ByTruncatingHead
//截去多余部分也不顯示省略號
label.lineBreakMode=NSLineBreakMode.ByClipping
//富文本設(shè)置
let attributeString =NSMutableAttributedString(string:"Welcome tostudy Swift !")
//從文本0開始6個字符字體HelveticaNeue-Bold,16號字體大小
attributeString.addAttribute(NSFontAttributeName, value:UIFont(name:"HelveticaNeue-Bold", size:16)!,range:NSMakeRange(0,6))
//設(shè)置字體顏色
attributeString.addAttribute(NSForegroundColorAttributeName, value:UIColor.blueColor(),range:NSMakeRange(0,3))
//設(shè)置文字背景顏色
attributeString.addAttribute(NSBackgroundColorAttributeName, value:UIColor.greenColor(),range:NSMakeRange(3,3))
label.attributedText= attributeString