屬性字段
UIFont *font = [UIFont systemFontOfSize:30];
//段落設(shè)置
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.lineSpacing = 10.0;//行間距
paragraph.paragraphSpacing = 20.0;//段落間距
paragraph.alignment = NSTextAlignmentJustified;//自動(dòng)換行
paragraph.firstLineHeadIndent = 30.0;//首行縮進(jìn)
// paragraph.headIndent = 50;//行首縮進(jìn),不包括首行
paragraph.tailIndent = -10;//行尾縮進(jìn)遂鹊,正數(shù)從左邊計(jì)算距離振乏,負(fù)數(shù)從右邊算起
/*
NSLineBreakByWordWrapping = 0, //自動(dòng)換行,單詞切斷
NSLineBreakByCharWrapping, //自動(dòng)換行秉扑,字母切斷
NSLineBreakByClipping, //非自動(dòng)換行慧邮,不切斷
NSLineBreakByTruncatingHead, //省略方式 ...abc
NSLineBreakByTruncatingTail, //省略方式 aa...bc
NSLineBreakByTruncatingMiddle //省略方式 abc...
*/
paragraph.lineBreakMode = NSLineBreakByCharWrapping;//斷行方式
// paragraph.baseWritingDirection = NSWritingDirectionRightToLeft;//句子方向
paragraph.paragraphSpacingBefore = 55;//段前距
paragraph.hyphenationFactor = 1;//連字符屬性调限,取值 0 到 1 之間,開(kāi)啟斷詞功能
//陰影
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor grayColor];
shadow.shadowOffset = CGSizeMake(2, 1);
NSDictionary *dic = @{NSFontAttributeName:font,//字體
NSParagraphStyleAttributeName:paragraph,//段落误澳,NSParagraphStyle對(duì)象
NSForegroundColorAttributeName:[UIColor orangeColor],//字體顏色
// NSBackgroundColorAttributeName:[UIColor grayColor],//字體背景色
NSLigatureAttributeName:@(1),//連字符
NSKernAttributeName:@(5),//字間距
NSStrikethroughStyleAttributeName:@(1),//刪除線0或1耻矮,NSNumber類(lèi)型
NSUnderlineStyleAttributeName:@(1),//下劃線
// NSStrokeColorAttributeName:[UIColor greenColor],//邊線顏色
// NSStrokeWidthAttributeName:@(1),//邊線寬度
NSShadowAttributeName:shadow,//陰影,NSShadow對(duì)象
NSVerticalGlyphFormAttributeName:@(0)//橫豎排版,iOS對(duì)0以外的未定義忆谓。
};
參考文章
iOS富文本
iOS 字符屬性NSAttributedString描述
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者