DLAttributedString
链式开发富文本
公司使用许多个性化文本,但使用系统提供的 NSMutableAttributedString 写起来实在冗余,可读性也很差。如果能像 Masonry 一样编写代码就完美了。不多说,直接上手。
安装
使用 orsome CocoaPods。
在您的 Podfile 中
pod 'DLAttributedString'
或者直接拖拽到项目中
使用该链式开发富文本有两种书写方式
第一种
NSMutableAttributedString *attributedStr = [NSMutableAttributedString attributedWithString:@"hello world"];
attributedStr.color(UIColor.redColor)
.bgColor(UIColor.yellowColor);
第二种
NSMutableAttributedString *attributedStr = [NSMutableAttributedString attributedWithString:@"hello world"];
attributedStr.color(UIColor.redColor).bgColor(UIColor.yellowColor);