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);
//富文本对象
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);