1.繼承鏈:UIview:UIresponder:NSObjecthtml
2.若是你想要使UIlabel可以和用戶進行互動,須要把它實例變量的屬性 userInteractionEnabled改成yes
app
3.若是想要在UIlabel的下拓展一個子視圖,須要把clipsToBounds的屬性變成no
佈局
4.能夠存取的屬性字體
(1)NSString *aString = @"我喜歡你";spa
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:aString];code
[attribute addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, 1)];htm
[attribute addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:25] range:NSMakeRange(0, 1)];繼承
label.attributedText = attribute;//經過這個屬性能夠改變內容字符串的屬性,如字體大小、字體顏色等事件
(2)label.font = [UIFont systemFontOfSize:20];//把標籤的字體發小改成20ip
(3)label.textColor = [UIColor greenColor]; //把標籤裏面的字體改成綠色
(4)label.textAlignment = NSTextAlignmentCenter;//把字設置在標籤的中央,還有left,right,natural,justified能夠選擇
(5)label.lineBreakMode = NSLineBreakByClipping; //若是標籤設置了只能寫一行,那麼寫完一行後字符串就會被截斷
(6)label.enabled = NO; //禁用一些屬性,例如文字顏色,這個屬性只禁用了標籤是怎麼創建的屬性
(7)label.adjustsFontSizeToFitWidth = YES;//設置文字只能最多恰好達到寬的邊界,但不能超過邊界
(8)label.numberOfLines = 1; //設置標籤的行數只有一行
(9)label.allowsDefaultTighteningForTruncation = YES; //容許在文字被截斷以前縮進字體間距從而容納更多的字
(10)label.baselineAdjustment = UIBaselineAdjustmentAlignCenters; //把標籤內的文字限制在標籤內部,不能超過邊界。同時這個屬性只能在行數爲1的時候才起做用
(11)label.minimumScaleFactor = 2.0; //若是沒有設置文字的大小,則文字的大小爲系統默認最小文字*2
(12)label.minimumScaleFactor = 2.0; //設置爲當前文字大小的2倍
(13)[label sizeToFit]; //設置標籤自動適應文字的大小
(14)label.highlightedTextColor = [UIColor blueColor]; //設置高光的時候文字的顏色爲藍色
label.highlighted = YES; //設置標籤的狀態爲高光
(15)label.shadowColor = [UIColor orangeColor]; //設置文字的陰影爲橙色
(16)label.shadowOffset = CGSizeMake(3, 3); //設置陰影的大小
(17)label.bounds = [label textRectForBounds:label.bounds limitedToNumberOfLines:0];//設置標籤的行數爲0,即行數不限制,而且令邊緣能夠隨文字的變化而變化
(18)CGRect textInRect = CGRectMake(100, 100, 10, 10);
[label drawTextInRect:textInRect]; //這方法不該該直接使用,應該讓子視圖重載來使用
(19)label.preferredMaxLayoutWidth = 40; //在佈局約束下,這個屬性能夠影響標籤的大小
(20)label.userInteractionEnabled = YES; //是否容許和用戶進行交互,是否能夠響應事件
(21)label.clipsToBounds = YES; // 是否讓子視圖遵照父視圖的大小