OC--链式编程实战(封装NSMutableAttributed
2017-03-04 本文已影响112人
啊哈呵
使用例子
NSString *text= @"说明:\n1、个人业绩为实时统计;\n2、奖励显示为T+1(当日办理隔日显示);\n3、无邀请码的订单不在个人业绩统计范畴;\n4、如对奖金有疑问,请向上级反馈处理。";
NSMutableAttributedString *att=[[NSMutableAttributedString alloc]initWithString:text];
//设置字号14、颜色、行间距
att.ps_font([UIFont systemFontOfSize:14.0]).ps_color(k_Color_9B9B9B).ps_lineSpacing(2);
//把全部“为”字变成红色、字间距为10
[att ps_changeSubStrings:@[@"为"] makeCalculators:^(NSMutableAttributedString *make) {
make.ps_color([UIColor redColor]).ps_kern(10);
}];
//把全部“@"个人",@"绩"变成绿色、字号19、设置笔画宽度(中空效果)
[att ps_changeSubStrings:@[@"个人",@"绩"] makeCalculators:^(NSMutableAttributedString *make) {
make.ps_color([UIColor greenColor]).ps_font([UIFont systemFontOfSize:19]).ps_strokeWidth(4);
}];
lab.attributedText=att;
效果
WX20170304-132522@2x.png直接上代码,NSMutableAttributedString属性太多,代码有点长
NSMutableAttributedString+Chain.h
#import <Foundation/Foundation.h>
@interface NSMutableAttributedString (Chain)
/**
改变某些文字的颜色 并单独设置其字体
@param subStrings 想要变色的字符数组
@param block 里面用make.各种想要的设置
*/
- (void)ps_changeSubStrings:(NSArray *)subStrings makeCalculators:(void (^)(NSMutableAttributedString * make))block;
/**
多个AttributedString连接
*/
- (void)ps_appendAttributedStrings:(NSArray *)attrStrings;
/**
多个AttributedString连接
*/
+ (NSMutableAttributedString *)ps_appendAttributedStrings:(NSArray *)attrStrings;
#pragma mark -基本设置
// NSFontAttributeName 设置字体属性,默认值:字体:Helvetica(Neue) 字号:12
// NSForegroundColorAttributeNam 设置字体颜色,取值为 UIColor对象,默认值为黑色
// NSBackgroundColorAttributeName 设置字体所在区域背景颜色,取值为 UIColor对象,默认值为nil, 透明色
// NSLigatureAttributeName 设置连体属性,取值为NSNumber 对象(整数),0 表示没有连体字符,1 表示使用默认的连体字符
// NSKernAttributeName 设定字符间距,取值为 NSNumber 对象(整数),正值间距加宽,负值间距变窄
// NSStrikethroughStyleAttributeName 设置删除线,取值为 NSNumber 对象(整数)
// NSStrikethroughColorAttributeName 设置删除线颜色,取值为 UIColor 对象,默认值为黑色
// NSUnderlineStyleAttributeName 设置下划线,取值为 NSNumber 对象(整数),枚举常量 NSUnderlineStyle中的值,与删除线类似
// NSUnderlineColorAttributeName 设置下划线颜色,取值为 UIColor 对象,默认值为黑色
// NSStrokeWidthAttributeName 设置笔画宽度,取值为 NSNumber 对象(整数),负值填充效果,正值中空效果
// NSStrokeColorAttributeName 填充部分颜色,不是字体颜色,取值为 UIColor 对象
// NSShadowAttributeName 设置阴影属性,取值为 NSShadow 对象
// NSTextEffectAttributeName 设置文本特殊效果,取值为 NSString 对象,目前只有图版印刷效果可用:
// NSBaselineOffsetAttributeName 设置基线偏移值,取值为 NSNumber (float),正值上偏,负值下偏
// NSObliquenessAttributeName 设置字形倾斜度,取值为 NSNumber (float),正值右倾,负值左倾
// NSExpansionAttributeName 设置文本横向拉伸属性,取值为 NSNumber (float),正值横向拉伸文本,负值横向压缩文本
// NSWritingDirectionAttributeName 设置文字书写方向,从左向右书写或者从右向左书写
// NSVerticalGlyphFormAttributeName 设置文字排版方向,取值为 NSNumber 对象(整数),0 表示横排文本,1 表示竖排文本
// NSLinkAttributeName 设置链接属性,点击后调用打开指定URL地址
// NSAttachmentAttributeName 设置文本附件,取值为NSTextAttachment对象,常用于文字图片混排
/**
.color(文字颜色)
*/
- (NSMutableAttributedString *(^)(UIColor *))ps_color;
/**
.ps_bgColor(背景颜色)
*/
- (NSMutableAttributedString *(^)(UIColor *))ps_bgColor;
/**
.font(字体)
*/
- (NSMutableAttributedString *(^)(UIFont *))ps_font;
/**
.ps_offset(偏移量) 正值上偏,负值下偏
*/
- (NSMutableAttributedString *(^)(CGFloat))ps_baselineOffset;
/**
.ps_ligature(连体符)设置连体属性,0 表示没有连体字符,1 表示使用默认的连体字符
*/
- (NSMutableAttributedString *(^)(NSInteger))ps_ligature;
/**
.ps_kern(字间距),取值为 NSNumber 对象(整数),正值间距加宽,负值间距变窄
*/
- (NSMutableAttributedString *(^)(NSInteger))ps_kern;
/**
.ps_strikethrough(删除线),取值为 NSNumber 对象(整数)
*/
- (NSMutableAttributedString *(^)(NSUnderlineStyle))ps_strikethrough;
/**
NSStrikethroughColorAttributeName 设置删除线颜色,取值为 UIColor 对象,默认值为黑色
*/
- (NSMutableAttributedString *(^)(UIColor *))ps_strikethroughColor;
/**
设置下划线,取值为 NSNumber 对象(整数),枚举常量 NSUnderlineStyle中的值,与删除线类似
*/
- (NSMutableAttributedString *(^)(NSUnderlineStyle))ps_underlineStyle;
/**
NSUnderlineColorAttributeName 设置下划线颜色,取值为 UIColor 对象,默认值为黑色
*/
- (NSMutableAttributedString *(^)(UIColor *))ps_underlineColor;
/**
NSStrokeWidthAttributeName 设置笔画宽度,取值为 NSNumber 对象(整数),负值填充效果,正值中空效果
*/
- (NSMutableAttributedString *(^)(NSInteger))ps_strokeWidth;
/**
NSStrokeColorAttributeName 填充部分颜色,不是字体颜色,取值为 UIColor 对象
*/
- (NSMutableAttributedString *(^)(UIColor *))ps_strokeColor;
/**
NSShadowAttributeName 设置阴影属性,取值为 NSShadow 对象
*/
- (NSMutableAttributedString *(^)(NSShadow *))ps_shadow;
/**
NSTextEffectAttributeName 设置文本特殊效果,取值为 NSString 对象,目前只有图版印刷效果可用:
*/
- (NSMutableAttributedString *(^)(NSString *))ps_textEffect;
/**
NSObliquenessAttributeName设置字形倾斜度,取值为 NSNumber (float),正值右倾,负值左倾
*/
- (NSMutableAttributedString *(^)(CGFloat))ps_obliqueness;
/**
NSExpansionAttributeName 设置文本横向拉伸属性,取值为 NSNumber (float),正值横向拉伸文本,负值横向压缩文本
*/
- (NSMutableAttributedString *(^)(CGFloat))ps_expansion;
/**
NSWritingDirectionAttributeName 设置文字书写方向NSWritingDirection
*/
- (NSMutableAttributedString *(^)(NSWritingDirection))ps_writingDirection;
/**
NSVerticalGlyphFormAttributeName 设置文字排版方向,取值为 NSNumber 对象(整数),0 表示横排文本,1 表示竖排文本
*/
- (NSMutableAttributedString *(^)(NSInteger))ps_verticalGlyph;
/**
NSLinkAttributeName 设置链接属性,点击后调用打开指定URL地址
*/
- (NSMutableAttributedString *(^)(NSURL *))ps_linkAttribute;
#pragma mark -NSParagraphStyleAttributeName 设置文本段落排版格式
//alignment //对齐方式
//lineSpacing //行距
//paragraphSpacing //段距
//firstLineHeadIndent //首行缩进
//headIndent //缩进
//tailIndent //尾部缩进
//lineBreakMode //断行方式
//maximumLineHeight //最大行高
//minimumLineHeight //最低行高
//paragraphSpacingBefore //段首空间
//baseWritingDirection //句子方向
//lineHeightMultiple //可变行高,乘因数。
//hyphenationFactor //连字符属性
/**
.alignment(对齐)
*/
- (NSMutableAttributedString *(^)(NSTextAlignment))ps_alignment;
/**
.lineSpacing(调整行间距)
*/
- (NSMutableAttributedString *(^)(CGFloat))ps_lineSpacing;
/**
.paragraphSpacing(调整段间距)
*/
- (NSMutableAttributedString *(^)(CGFloat))ps_paragraphSpacing;
/**
首行缩进
*/
- (NSMutableAttributedString *(^)(CGFloat ))ps_firstLineHeadIndent;
/**
缩进
*/
- (NSMutableAttributedString *(^)(CGFloat ))ps_headIndent;
/**
尾部缩进
*/
- (NSMutableAttributedString *(^)(CGFloat ))ps_tailIndent;
/**
断行方式
*/
- (NSMutableAttributedString *(^)(NSLineBreakMode ))ps_lineBreakMode;
/**
最大行高
*/
- (NSMutableAttributedString *(^)(CGFloat ))ps_maximumLineHeight;
/**
最低行高
*/
- (NSMutableAttributedString *(^)(CGFloat ))ps_minimumLineHeight;
/**
句子方向
*/
- (NSMutableAttributedString *(^)(NSWritingDirection ))ps_baseWritingDirection;
/**
可变行高,乘因数。
*/
- (NSMutableAttributedString *(^)(CGFloat ))ps_lineHeightMultiple;
/**
连字符属性。
*/
- (NSMutableAttributedString *(^)(CGFloat ))ps_hyphenationFactor;
@end
NSMutableAttributedString+Chain.m
#import "NSMutableAttributedString+Chain.h"
#import <objc/runtime.h>
@interface NSMutableAttributedString ()
@property(nonatomic, assign) NSRange changeRange;
@end
@implementation NSMutableAttributedString (Chain)
/**
改变某些文字的颜色 并单独设置其字体
@param subStrings 想要变色的字符数组
@param block 里面用make.各种想要的设置
*/
- (void)ps_changeSubStrings:(NSArray *)subStrings makeCalculators:(void (^)(NSMutableAttributedString * make))block{
for (NSString *rangeStr in subStrings) {
NSMutableArray *array = [self ps_getRangeWithTotalString:self.string SubString:rangeStr];
for (NSNumber *rangeNum in array) {
//设置修改range
self.changeRange = [rangeNum rangeValue];
//block 链式调用
block(self);
}
}
//设置为空
self.changeRange=NSMakeRange(0, 0);
}
/**
多个AttributedString连接
*/
- (void)ps_appendAttributedStrings:(NSArray *)attrStrings{
for (NSAttributedString *att in attrStrings) {
[self appendAttributedString:att];
}
}
/**
多个AttributedString连接
*/
+ (NSMutableAttributedString *)ps_appendAttributedStrings:(NSArray *)attrStrings{
NSMutableAttributedString *att=[NSMutableAttributedString new];
[att ps_appendAttributedStrings:attrStrings];
return att;
}
#pragma mark - Private Methods
/**
* 获取某个字符串中子字符串的位置数组
* @param totalString 总的字符串
* @param subString 子字符串
* @return 位置数组
*/
- (NSMutableArray *)ps_getRangeWithTotalString:(NSString *)totalString SubString:(NSString *)subString {
if (subString == nil && [subString isEqualToString:@""]) {
return nil;
}
NSMutableArray *arrayRanges = [NSMutableArray array];
//方法一、NSRegularExpression
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:subString options:0 error:nil];
NSArray *matches = [regex matchesInString:totalString options:0 range:NSMakeRange(0, totalString.length)];
for(NSTextCheckingResult *result in [matches objectEnumerator]){
NSRange matchRange = [result range];
[arrayRanges addObject:[NSNumber valueWithRange:matchRange]];
}
return arrayRanges;
//方法二、[NSString componentsSeparatedByString:]分解得到数组,在用数组捣鼓出ranges
/*
NSArray *array=[totalString componentsSeparatedByString:subString];
NSInteger d=0;
for (int i=0; i<array.count-1; i++) {
NSString *string=array[i];
NSRange range=NSMakeRange(d+string.length, subString.length);
d=NSMaxRange(range);
[arrayRanges addObject:[NSNumber valueWithRange:range]];
}
return arrayRanges;
*/
//方法三、rangeOfString 查找
/*
NSRange searchRange = NSMakeRange(0, [totalString length]);
NSRange range=NSMakeRange(0, 0);
while ((range = [totalString rangeOfString:subString options:0 range:searchRange]).location != NSNotFound) {
[arrayRanges addObject:[NSNumber valueWithRange:range]];
searchRange = NSMakeRange(NSMaxRange(range), searchRange.length - NSMaxRange(range));
}
return arrayRanges;
*/
}
- (void)ps_addAttribute:(NSString *)name value:(id)value{
NSRange range=[self range];
if (range.length>0) {
[self addAttribute:name value:value range:range];
}else{
NSLog(@"AttributedString的string为空,注意!!!");
}
}
//获取有效的range
- (NSRange)range{
NSRange range=NSMakeRange(0, 0);
NSString *string=self.string;
if (string&&string.length>0) {
if (self.changeRange.length>0&&NSMaxRange(self.changeRange)<=string.length) {
//如果是需要修改的字符,就使用changeRange
range=self.changeRange;
}else{
//设置全部字符串
range=NSMakeRange(0, string.length);
}
}
return range;
}
- (NSMutableParagraphStyle *)ps_paragraphStyle{
NSRange range=[self range];
if (range.length>0) {
NSDictionary *dic = [self attributesAtIndex:0 effectiveRange:&range];
NSMutableParagraphStyle *paragraphStyle=dic[@"NSParagraphStyle"];
//如果字符串里面没有paragraphStyle,new一个新的
if (!paragraphStyle) {
paragraphStyle=[[NSMutableParagraphStyle alloc]init];
}
return paragraphStyle;
}else{
NSLog(@"AttributedString的string为空,注意!!!");
return nil;
}
}
#pragma mark -ChangeRange的get、set
-(void)setChangeRange:(NSRange)changeRange{
objc_setAssociatedObject(self, @selector(changeRange), [NSNumber valueWithRange:changeRange], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(NSRange)changeRange{
NSNumber *rangeNum = objc_getAssociatedObject(self, @selector(changeRange));
NSRange range = [rangeNum rangeValue];
return range;
}
#pragma mark - 设置各种配置参数
//颜色
- (NSMutableAttributedString *(^)(UIColor *))ps_color{
return ^NSMutableAttributedString *(UIColor *obj) {
[self ps_addAttribute:NSForegroundColorAttributeName value:obj];
return self;
};
}
/**
.ps_bgColor(背景颜色)
*/
- (NSMutableAttributedString *(^)(UIColor *))ps_bgColor{
return ^NSMutableAttributedString *(UIColor *obj) {
[self ps_addAttribute:NSBackgroundColorAttributeName value:obj];
return self;
};
}
//字体
- (NSMutableAttributedString *(^)(UIFont *))ps_font{
return ^NSMutableAttributedString *(UIFont *obj) {
[self ps_addAttribute:NSFontAttributeName value:obj];
return self;
};
}
//偏移量
- (NSMutableAttributedString *(^)(CGFloat ))ps_baselineOffset{
return ^NSMutableAttributedString *(CGFloat obj) {
[self ps_addAttribute:NSBaselineOffsetAttributeName value:@(obj)];
return self;
};
}
//.ps_ligature(连体符)设置连体属性,0 表示没有连体字符,1 表示使用默认的连体字符
- (NSMutableAttributedString *(^)(NSInteger))ps_ligature{
return ^NSMutableAttributedString *(NSInteger obj) {
[self ps_addAttribute:NSLigatureAttributeName value:@(obj)];
return self;
};
}
//.ps_kern(字间距),取值为 NSNumber 对象(整数),正值间距加宽,负值间距变窄
- (NSMutableAttributedString *(^)(NSInteger))ps_kern{
return ^NSMutableAttributedString *(NSInteger obj) {
[self ps_addAttribute:NSKernAttributeName value:@(obj)];
return self;
};
}
//.ps_strikethrough(删除线),NSUnderlineStyle
- (NSMutableAttributedString *(^)(NSUnderlineStyle))ps_strikethrough{
return ^NSMutableAttributedString *(NSUnderlineStyle obj) {
[self ps_addAttribute:NSStrikethroughStyleAttributeName value:@(obj)];
return self;
};
}
//NSStrikethroughColorAttributeName 设置删除线颜色,取值为 UIColor 对象,默认值为黑色
- (NSMutableAttributedString *(^)(UIColor *))ps_strikethroughColor{
return ^NSMutableAttributedString *(UIColor *obj) {
[self ps_addAttribute:NSStrikethroughStyleAttributeName value:obj];
return self;
};
}
//设置下划线,取值为 NSNumber 对象(整数),枚举常量 NSUnderlineStyle中的值,与删除线类似
- (NSMutableAttributedString *(^)(NSUnderlineStyle))ps_underlineStyle{
return ^NSMutableAttributedString *(NSUnderlineStyle obj) {
[self ps_addAttribute:NSUnderlineStyleAttributeName value:@(obj)];
return self;
};
}
//NSUnderlineColorAttributeName 设置下划线颜色,取值为 UIColor 对象,默认值为黑色
- (NSMutableAttributedString *(^)(UIColor *))ps_underlineColor{
return ^NSMutableAttributedString *(UIColor *obj) {
[self ps_addAttribute:NSUnderlineColorAttributeName value:obj];
return self;
};
}
//NSStrokeWidthAttributeName 设置笔画宽度,取值为 NSNumber 对象(整数),负值填充效果,正值中空效果
- (NSMutableAttributedString *(^)(NSInteger))ps_strokeWidth{
return ^NSMutableAttributedString *(NSInteger obj) {
[self ps_addAttribute:NSStrokeWidthAttributeName value:@(obj)];
return self;
};
}
//NSStrokeColorAttributeName 填充部分颜色,不是字体颜色,取值为 UIColor 对象
- (NSMutableAttributedString *(^)(UIColor *))ps_strokeColor{
return ^NSMutableAttributedString *(UIColor *obj) {
[self ps_addAttribute:NSStrokeColorAttributeName value:obj];
return self;
};
}
//NSShadowAttributeName 设置阴影属性,取值为 NSShadow 对象
- (NSMutableAttributedString *(^)(NSShadow *))ps_shadow{
return ^NSMutableAttributedString *(NSShadow *obj) {
[self ps_addAttribute:NSShadowAttributeName value:obj];
return self;
};
}
//NSTextEffectAttributeName 设置文本特殊效果,取值为 NSString 对象,目前只有图版印刷效果可用:
- (NSMutableAttributedString *(^)(NSString *))ps_textEffect{
return ^NSMutableAttributedString *(NSString *obj) {
[self ps_addAttribute:NSTextEffectAttributeName value:obj];
return self;
};
}
//NSObliquenessAttributeName设置字形倾斜度,取值为 NSNumber (float),正值右倾,负值左倾
- (NSMutableAttributedString *(^)(CGFloat))ps_obliqueness{
return ^NSMutableAttributedString *(CGFloat obj) {
[self ps_addAttribute:NSObliquenessAttributeName value:@(obj)];
return self;
};
}
//NSExpansionAttributeName 设置文本横向拉伸属性,取值为 NSNumber (float),正值横向拉伸文本,负值横向压缩文本
- (NSMutableAttributedString *(^)(CGFloat))ps_expansion{
return ^NSMutableAttributedString *(CGFloat obj) {
[self ps_addAttribute:NSExpansionAttributeName value:@(obj)];
return self;
};
}
//NSWritingDirectionAttributeName 设置文字书写方向NSWritingDirection
- (NSMutableAttributedString *(^)(NSWritingDirection))ps_writingDirection{
return ^NSMutableAttributedString *(NSWritingDirection obj) {
[self ps_addAttribute:NSWritingDirectionAttributeName value:@(obj)];
return self;
};
}
//NSVerticalGlyphFormAttributeName 设置文字排版方向,取值为 NSNumber 对象(整数),0 表示横排文本,1 表示竖排文本
- (NSMutableAttributedString *(^)(NSInteger))ps_verticalGlyph{
return ^NSMutableAttributedString *(NSInteger obj) {
[self ps_addAttribute:NSVerticalGlyphFormAttributeName value:@(obj)];
return self;
};
}
//NSLinkAttributeName 设置链接属性,点击后调用打开指定URL地址
- (NSMutableAttributedString *(^)(NSURL *))ps_linkAttribute{
return ^NSMutableAttributedString *(NSURL *obj) {
[self ps_addAttribute:NSLinkAttributeName value:obj];
return self;
};
}
//NSAttachmentAttributeName 设置文本附件,取值为NSTextAttachment对象,常用于文字图片混排
/*
NSTextAttachment *textAttachment01 = [[NSTextAttachment alloc] init];
textAttachment01.image = [UIImage imageNamed: @"10000.jpeg"]; //设置图片源
textAttachment01.bounds = CGRectMake(0, 0, 30, 30); //设置图片位置和大小
NSMutableAttributedString *attrStr01 = [[NSMutableAttributedString alloc] initWithString: originStr];
[attrStr01 addAttribute: NSFontAttributeName value: [UIFont systemFontOfSize: 25] range: NSMakeRange(0, originStr.length)];
NSAttributedString *attrStr11 = [NSAttributedString attributedStringWithAttachment: textAttachment01];
[attrStr01 insertAttributedString: attrStr11 atIndex: 2]; //NSTextAttachment占用一个字符长度,插入后原字符串长度增加1
_label01.attributedText = attrStr01;
*/
#pragma mark -NSParagraphStyleAttributeName 设置文本段落排版格式
//对齐
- (NSMutableAttributedString *(^)(NSTextAlignment))ps_alignment{
return ^NSMutableAttributedString *(NSTextAlignment obj) {
NSMutableParagraphStyle *style=[self ps_paragraphStyle];
style.alignment=obj;
[self ps_addAttribute:NSParagraphStyleAttributeName value:style];
return self;
};
}
//行间距
- (NSMutableAttributedString *(^)(CGFloat ))ps_lineSpacing{
return ^NSMutableAttributedString *(CGFloat obj) {
NSMutableParagraphStyle *style=[self ps_paragraphStyle];
style.lineSpacing=obj;
[self ps_addAttribute:NSParagraphStyleAttributeName value:style];
return self;
};
}
//段间距
- (NSMutableAttributedString *(^)(CGFloat ))ps_paragraphSpacing{
return ^NSMutableAttributedString *(CGFloat obj) {
NSMutableParagraphStyle *style=[self ps_paragraphStyle];
style.paragraphSpacing=obj;
[self ps_addAttribute:NSParagraphStyleAttributeName value:style];
return self;
};
}
//首行缩进
- (NSMutableAttributedString *(^)(CGFloat ))ps_firstLineHeadIndent{
return ^NSMutableAttributedString *(CGFloat obj) {
NSMutableParagraphStyle *style=[self ps_paragraphStyle];
style.firstLineHeadIndent=obj;
[self ps_addAttribute:NSParagraphStyleAttributeName value:style];
return self;
};
}
//缩进
- (NSMutableAttributedString *(^)(CGFloat ))ps_headIndent{
return ^NSMutableAttributedString *(CGFloat obj) {
NSMutableParagraphStyle *style=[self ps_paragraphStyle];
style.headIndent=obj;
[self ps_addAttribute:NSParagraphStyleAttributeName value:style];
return self;
};
}
//尾部缩进
- (NSMutableAttributedString *(^)(CGFloat ))ps_tailIndent{
return ^NSMutableAttributedString *(CGFloat obj) {
NSMutableParagraphStyle *style=[self ps_paragraphStyle];
style.tailIndent=obj;
[self ps_addAttribute:NSParagraphStyleAttributeName value:style];
return self;
};
}
//断行方式
- (NSMutableAttributedString *(^)(NSLineBreakMode ))ps_lineBreakMode{
return ^NSMutableAttributedString *(NSLineBreakMode obj) {
NSMutableParagraphStyle *style=[self ps_paragraphStyle];
style.lineBreakMode=obj;
[self ps_addAttribute:NSParagraphStyleAttributeName value:style];
return self;
};
}
//最大行高
- (NSMutableAttributedString *(^)(CGFloat ))ps_maximumLineHeight{
return ^NSMutableAttributedString *(CGFloat obj) {
NSMutableParagraphStyle *style=[self ps_paragraphStyle];
style.maximumLineHeight=obj;
[self ps_addAttribute:NSParagraphStyleAttributeName value:style];
return self;
};
}
//最低行高
- (NSMutableAttributedString *(^)(CGFloat ))ps_minimumLineHeight{
return ^NSMutableAttributedString *(CGFloat obj) {
NSMutableParagraphStyle *style=[self ps_paragraphStyle];
style.minimumLineHeight=obj;
[self ps_addAttribute:NSParagraphStyleAttributeName value:style];
return self;
};
}
//句子方向
- (NSMutableAttributedString *(^)(NSWritingDirection ))ps_baseWritingDirection{
return ^NSMutableAttributedString *(NSWritingDirection obj) {
NSMutableParagraphStyle *style=[self ps_paragraphStyle];
style.baseWritingDirection=obj;
[self ps_addAttribute:NSParagraphStyleAttributeName value:style];
return self;
};
}
//可变行高,乘因数
- (NSMutableAttributedString *(^)(CGFloat ))ps_lineHeightMultiple{
return ^NSMutableAttributedString *(CGFloat obj) {
NSMutableParagraphStyle *style=[self ps_paragraphStyle];
style.lineHeightMultiple=obj;
[self ps_addAttribute:NSParagraphStyleAttributeName value:style];
return self;
};
}
//连字符属性
- (NSMutableAttributedString *(^)(CGFloat ))ps_hyphenationFactor{
return ^NSMutableAttributedString *(CGFloat obj) {
NSMutableParagraphStyle *style=[self ps_paragraphStyle];
style.hyphenationFactor=obj;
[self ps_addAttribute:NSParagraphStyleAttributeName value:style];
return self;
};
}
@end