NSAttributedString屬性

屬性字段
UIFont *font = [UIFont systemFontOfSize:30];
    
    //段落設置
    NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
    paragraph.lineSpacing = 10.0;//行間距
    paragraph.paragraphSpacing = 20.0;//段落間距
    paragraph.alignment = NSTextAlignmentJustified;//自動換行
    paragraph.firstLineHeadIndent = 30.0;//首行縮進
//    paragraph.headIndent = 50;//行首縮進,不包括首行
    paragraph.tailIndent = -10;//行尾縮進,正數從左邊計算距離,負數從右邊算起
    
    /*
     NSLineBreakByWordWrapping = 0, //自動換行,單詞切斷
     NSLineBreakByCharWrapping,    //自動換行,字母切斷
     NSLineBreakByClipping,         //非自動換行,不切斷 
     NSLineBreakByTruncatingHead,   //省略方式  ...abc
     NSLineBreakByTruncatingTail,   //省略方式  aa...bc
     NSLineBreakByTruncatingMiddle  //省略方式  abc...
     */
    paragraph.lineBreakMode = NSLineBreakByCharWrapping;//斷行方式
//    paragraph.baseWritingDirection = NSWritingDirectionRightToLeft;//句子方向
    paragraph.paragraphSpacingBefore = 55;//段前距
    paragraph.hyphenationFactor = 1;//連字符屬性,取值 0 到 1 之間,開啟斷詞功能
    
    //陰影
    NSShadow *shadow = [[NSShadow alloc] init];
    shadow.shadowColor = [UIColor grayColor];
    shadow.shadowOffset = CGSizeMake(2, 1);
    
    NSDictionary *dic = @{NSFontAttributeName:font,//字體
                          NSParagraphStyleAttributeName:paragraph,//段落,NSParagraphStyle對象
                          NSForegroundColorAttributeName:[UIColor orangeColor],//字體顏色
//                          NSBackgroundColorAttributeName:[UIColor grayColor],//字體背景色
                          NSLigatureAttributeName:@(1),//連字符
                          NSKernAttributeName:@(5),//字間距
                          NSStrikethroughStyleAttributeName:@(1),//刪除線0或1,NSNumber類型
                          NSUnderlineStyleAttributeName:@(1),//下劃線
//                          NSStrokeColorAttributeName:[UIColor greenColor],//邊線顏色
//                          NSStrokeWidthAttributeName:@(1),//邊線寬度
                          NSShadowAttributeName:shadow,//陰影,NSShadow對象
                          NSVerticalGlyphFormAttributeName:@(0)//橫豎排版,iOS對0以外的未定義。
                          
                          };

參考文章
iOS富文本
iOS 字符屬性NSAttributedString描述

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容