项目介绍:
对比:
之前:
NSShadow *shadow = [NSShadow new];
shadow.shadowColor = [UIColor orangeColor];
shadow.shadowOffset = CGSizeMake(0.2, 0.2);
NSAttributedString *testAttr = [[NSAttributedString alloc] initWithString:@"test" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:[UIColor redColor], NSShadowAttributeName:shadow}];
现在:
// 可修改整体, 也可修改指定范围.
testAttr = [SJAttributesFactory alterStr:@"test" block:^(SJAttributesFactory *worker) {
// 修改整体
worker.font([UIFont systemFontOfSize:12])
.expansion(0.5)
.fontColor([UIColor redColor])
.shadow(shadow)
.backgroundColor([UIColor greenColor])
.lineSpacing(5)
.alignment(NSTextAlignmentLeft)
.underline([UIColor redColor]); // 等等
// 修改指定范围
worker.nextFont([UIFont systemFontOfSize:20])
.nextFontColor([UIColor yellowColor])
.nextOffset(0.3)
.nextLetterpress()
.range(NSMakeRange(1, 2)); // 指定范围
}];
Use
pod 'SJAttributesFactory'
项目地址
https://github.com/changsanjiang/SJAttributesFactory