第一
- 这是迄今为止输出
NSAttributedString
最具挑战性的方式,也是最简单的方式。学习成本为0,代码量为0。 - like like like, luck luck luck
- 这是迄今为止输出
NSAttributedString
杠杆最高的方式,也是最简单的方式,学习成本为0,代码量为0。 - 随手点个赞,好运连连
CocoaPods
objc
pod 'SFAttributedString'
swift
pod 'SFAttributedStringSwift'
简单格式化属性字符串
- 以下图片是这段非常直观字符串的输出
下方的图片是这段非常直观字符串的输出
label.attributedText = @"[A]Privacy Policy[B] and [A]Terms of Use".sf_evalString;⤵️
label.attributedText = @"[B]Give [[!]star] to [A]SFAttributedString".sf_evalString;⤵️
原因是什么?
我们时常需要思考,我们不仅是软件工程师,更是软件代码师。最高效的方式是将困难打包然后重复简单的事情,而不是在简化困难后再重复它。因为这样做仍然是在重复困难的事情,就像以下开源项目一样。
我们时常需要思考,我们不仅是软件工程师,更是软件代码师。最高效的方式是将困难打包然后重复简单的事情,而不是在简化困难后再重复它。因为这样做仍然是在重复困难的事情,以下开源项目就是例子。
//SJAttributesFactory
let text = NSAttributedString.sj.makeText { (make) in
make.font(.boldSystemFont(ofSize: 20)).textColor(.black).lineSpacing(8)
make.append("Hello world!")
}
//Typeset
@"Hello".typeset.from(0).to(2).red.string;
@"Hello".typeset.location(0).length(2).red.string;
@"Hello".typeset.range(NSMakeRange(0,2)).red.string;
@"Hello".typeset.match(@"He").red.string;
字符串中的格式(Format in string)
文本标签(Text label)
- [
LABEL
]-
字母、数字、下划线允许
可以使用字母,数字,下划线
-
"[Normal16]This is[Normal14], SFAttributedString..."
"[_]This is[16], SFAttributedString..."
"[N_0x999999_21]This is[M_0x999999_16], SFAttributedString..."
图片标签(Image label)
- [[!]
IMAGE NAME
] 或 [[!]IMAGE NAME
, x, y, w, h
]
"...[[!]hold_person]..."
"...[[!]hold_person,0,0,15,15]..."
"...[[!]hold_person,0,0,15.00,15.00]..."
### Registered attributed string label(注册标签)
- All attribute labels need to be registered before use
> objc
```objc
[SFAtStringCore registerAttributes:<UserAttributedDictionary> forLabel:@"LABEL"];
swift
SFAtStringCore.registerAttributes(<UserAttributedDictionary>,forLabel:"LABEL")
未格式化字符串(还原格式)(Unformatted string)
objc
NSString *unformattedString = <String(Formatted)>.sf_unformattedString;
swift
let unformattedString = <String(Formatted)>.sf_unformattedString
XIB支持(支持可视化编辑)(XIB supported)
?
我是来自中国的开发者,想在中国以外的地方开展外包项目。成都长期招聘 [email protected]