美文网首页
NSAttributedString属性

NSAttributedString属性

作者: iOS_Xue | 来源:发表于2016-08-04 18:10 被阅读158次
属性字段
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描述

相关文章

网友评论

      本文标题:NSAttributedString属性

      本文链接:https://www.haomeiwen.com/subject/csofsttx.html