富文本


富文本设置(NSMutableAttributedString)

  • 特性

     NSFontAttributeName              //  字体属性NSFonr, defualt (Helvetica,12)
     NSForegroundColorAttributeName   //  字体颜色UIColor, default (黑)
     NSBackgroundColorAttributeName   //  字体所在区域背景颜色UIColor, default (nil,透明色)
     NSLigatureAttributeName   //  连体属性NSNumber, 0 (没有连体字符); 1 (使用默认的连体字符)
     NSKernAttributeName       //  字符间距NSNumber, 正数(加宽); 负值(变小)
     NSStrikethroughStyleAttributeName   //  删除线NSNumber(整数)
     NSStrikethroughColorAttributeName   //  删除线颜色UIColor, default (黑)
     NSUnderlineStyleAttributeName       //  下划线NSNumber(整数),枚举常量 NSUnderlineStyle中的值,与删除线类似
     NSUnderlineColorAttributeName       //   下划线颜色UIColor, default (黑)
     NSStrokeWidthAttributeName          //   笔画宽度NSNumber, 负值填充效果; 正值中空效果
     NSStrokeColorAttributeName          //  部分颜色,不是字体颜色UIColor
     NSShadowAttributeName               //  阴影属性NSShadow
     NSTextEffectAttributeName           //  文本特殊效果NSString, 目前只有图版印刷效果可用:
     NSBaselineOffsetAttributeName       //  基线偏移值NSNumber(float),正值上偏;负值下偏
     NSObliquenessAttributeName          //  字形倾斜度NSNumber, 正值右倾; 负值左倾
     NSExpansionAttributeName            //  文本横向拉伸属性NSNumber(float),正值横向拉伸文本; 负值横向压缩文本
     NSWritingDirectionAttributeName     //  文字书写方向,从左向右书写或者从右向左书写
     NSVerticalGlyphFormAttributeName    //  文字排版方向NSNumber(整数), 0 表示横排文本; 1 表示竖排文本
     NSLinkAttributeName                 //  链接属性,点击后调用浏览器打开指定URL地址
     NSAttachmentAttributeName           //  文本附件NSTextAttachment, 常用于文字图片混排 
     NSParagraphStyleAttributeName       //  文本段落排版格式NSParagraphStyle 对象
    
  • 代码

     //  1、创建NSMutableAttributedString
     NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:@"啦啦啦"];
     //  作用范围
     NSRange range = NSMakeRange(0, 2);
     //  添加特性
     [attrString addAttribute:<#(nonnull NSString *)#> value:<#(nonnull id)#> range:<#(NSRange)#>];
     UILabel *label = [[UILabel alloc] init];
     label.attributedText = attrString;
    

results matching ""

    No results matching ""