UILabel *pLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,100,200,100)];測試
pLabel.text = @"測試到嗎";字體
NSInteger leght = [pLabel.text length];it
NSMutableAttributedString *richText = [[NSMutableAttributedString alloc] initWithString:pLabel.text];table
//設置特殊字段的大小,顏色,字體樣式
[richText addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:16.0] range:NSMakeRange(0, leght)];//設置字體大小tab
[richText addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, leght)];//設置字體顏色字符
[richText addAttribute:NSObliquenessAttributeName value:@1 range:NSMakeRange(0, leght)];//設置的是斜體參數
[richText addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleDouble] range:NSMakeRange(0, leght)];//設置下劃線顏色
[richText addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0,leght)];//設置刪除線像素
[richText addAttribute:NSStrikethroughColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, leght)];//設置刪除線的顏色
//屬性參數
NSFontAttributeName //字體 默認是12號
NSParagraphStyleAttributeName//段落樣式
NSForegroundColorAttributeName//指定字體顏色
NSBackgroundColorAttributeName//字體背景顏色
NSLigatureAttributeName//連體字符
NSKernAttributeName//字距的像素
NSStrikethroughStyleAttributeName//指定字上加刪除線
NSUnderlineStyleAttributeName//指定字加下劃線
NSStrokeColorAttributeName//填充部分顏色
NSStrokeWidthAttributeName//填充寬度
NSShadowAttributeName//陰影
NSUnderlineColorAttributeName//下劃線顏色