SFAttributedStringSwift 1.0.1

SFAttributedStringSwift 1.0.1

Novo 维护。



  • Meterwhite

Logo

第一

  • 这是迄今为止输出 NSAttributedString 最具杠杆的方式,也是最简单的方式。学习成本为 0,代码量为 0。
  • 赞一个,好运挡不住
  • 这是迄今为止输出NSAttributedString杠杆最高的方式,也是最简单的方式,学习成本为0,代码量为0。
  • 随手赞一赞,好运上百万

CocoaPods

objc

pod 'SFAttributedString'

swift

pod 'SFAttributedStringSwift'

简单的格式化富文本字符串

  • 下面这张图片是这段非常直观的字符串的输出

    下方图片是这段非常直观的字符串的输出

label.attributedText = @"[A]Privacy Policy[B] and [A]Terms of Use".sf_evalString;⤵️

SFAttributedString icon

label.attributedText = @"[B]Give [[!]star] to [A]SFAttributedString".sf_evalString;⤵️

SFAttributedString icon

为什么?

我们常常认为我们是软件工程师,而不是软件代码师。最高效的方式是将困难封装,然后重复简单的事情,而不是在困难减少后再重复它,因为这样做仍然在重复困难的事情。下面是一些开源项目的例子。

我们常常认为我们是软件工程师,而不是软件代码师。最高效的方式是将困难封装,然后重复简单的事情,而不是在困难减少后再重复它,因为这样做仍然在重复困难的事情。下面是一些开源项目的例子。

//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;

字符串中的格式

文本标签

  • [ LABEL]
    • 允许使用字母,数字和下划线

      可以使用字母,数字,下划线

"[Normal16]This is[Normal14], SFAttributedString..."

"[_]This is[16], SFAttributedString..."

"[N_0x999999_21]This is[M_0x999999_16], SFAttributedString..."

图片标签

  • [[!]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")

还原格式

objc

NSString *unformattedString = <String(Formatted)>.sf_unformattedString;

swift

let unformattedString = <String(Formatted)>.sf_unformattedString

支持可视化编辑

IBInspectable icon


?

我是来自中国的开发者,想在中国以外的地方开发外包项目。成都长期求职 [email protected]