NSAttributedString用法

  NSString * str = @"(含代)";


//富文本对象
     NSMutableAttributedString * aAttributedString = [[NSMutableAttributedString alloc] initWithString:str];


//富文本样式
     [aAttributedString addAttribute:NSForegroundColorAttributeName  //文字颜色
                               value:[UIColor redColor]
                              range:NSMakeRange(str.length-4, 4)];


[aAttributedString addAttribute:NSFontAttributeName             //文字字体
                              value:[UIFont systemFontOfSize:25]
                               range:NSMakeRange(0, 4)];
    
     lebel.attributedText = aAttributedString;


//段落样式
     NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
 #warning  lable.numberOfLines必须为0,段落样式才生效
     //行间距
    paragraphStyle.lineSpacing = 10.0;
     //段落间距
     paragraphStyle.paragraphSpacing = 20.0;


[attributedString addAttribute:NSParagraphStyleAttributeName
                             value:paragraphStyle
                              range:NSMakeRange(0, string.length)];
lable.attributedText = attributedString;


[段落样式-插曲]
 1 @property(readwrite) CGFloat lineSpacing;              //行间距
 2 @property(readwrite) CGFloat paragraphSpacing;           //段间距
 3 @property(readwrite) NSTextAlignment alignment;           //对齐方式
 4 @property(readwrite) CGFloat firstLineHeadIndent;          //首行缩紧
 5 @property(readwrite) CGFloat headIndent;               //除首行之外其他行缩进
 6 @property(readwrite) CGFloat tailIndent;               //每行容纳字符的宽度
 7 @property(readwrite) NSLineBreakMode lineBreakMode;         //换行方式
 8 @property(readwrite) CGFloat minimumLineHeight;           //最小行高
 9 @property(readwrite) CGFloat maximumLineHeight;           //最大行高
10 @property(readwrite) NSWritingDirection baseWritingDirection;  //书写方式(NSWritingDirectionNatural,NSWritingDirectionLeftToRight,NSWritingDirectionRightToLeft)
11 @property(readwrite) CGFloat lineHeightMultiple;
12 @property(readwrite) CGFloat paragraphSpacingBefore;
13 @property(readwrite) float hyphenationFactor;
14 @property(readwrite,copy,NS_NONATOMIC_IOSONLY) NSArray *tabStops NS_AVAILABLE_IOS(7_0);
15 @property(readwrite,NS_NONATOMIC_IOSONLY) CGFloat defaultTabInterval NS_AVAILABLE_IOS(7_0);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值