UILabel中的AttributedText屬性使用

UILabel *pLabel = [[UILabel alloc]?initWithFrame:CGRectMake(0,100,200,100)];

pLabel.text = @"測(cè)試到嗎";

NSInteger leght = [pLabel.text length];

NSMutableAttributedString?*richText = [[NSMutableAttributedString?alloc]?initWithString:pLabel.text];

//設(shè)置特殊字段的大小,顏色,字體

[richText?addAttribute:NSFontAttributeName?value:[UIFont?boldSystemFontOfSize:16.0]?range:NSMakeRange(0, leght)];//設(shè)置字體大小

[richText?addAttribute:NSForegroundColorAttributeNamevalue:[UIColor redColor]?range:NSMakeRange(0, leght)];//設(shè)置字體顏色

[richText?addAttribute:NSObliquenessAttributeName?value:@1?range:NSMakeRange(0, leght)];//設(shè)置的是斜體

[richText?addAttribute:NSUnderlineStyleAttributeName?value:[NSNumber?numberWithInteger:NSUnderlineStyleDouble]?range:NSMakeRange(0,?leght)];//設(shè)置下劃線

[richText addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0,leght)];//設(shè)置刪除線

[richText addAttribute:NSStrikethroughColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, leght)];//設(shè)置刪除線的顏色

//屬性參數(shù)

NSFontAttributeName //字體 默認(rèn)是12號(hào)

NSParagraphStyleAttributeName//段落樣式

NSForegroundColorAttributeName//指定字體顏色

NSBackgroundColorAttributeName//字體背景顏色

NSLigatureAttributeName//連體字符

NSKernAttributeName//字距的像素

NSStrikethroughStyleAttributeName//指定字上加刪除線

NSUnderlineStyleAttributeName//指定字加下劃線

NSStrokeColorAttributeName//填充部分顏色

NSStrokeWidthAttributeName//填充寬度

NSShadowAttributeName//陰影

NSUnderlineColorAttributeName//下劃線顏色

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容