CuteAttribute 1.2.4

CuteAttribute 1.2.4

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新发布2019年3月
SPM支持 SPM

qiuncheng 维护。



  • 作者:
  • qiuncheng

CuteAttribute

Build Status Carthage compatible pod version GitHub license

Swift 中处理富文本字符串的一种优雅方式。使用 .cute 可以方便地创建富文本字符串,无论从 StringNSStringNSAttributedStringNSMutableAttributedString。它非常神奇,几乎所有方法都支持 链式调用。之所以创建这个项目,是因为几天前遇到了 Typeset。但发现 Swift 使用它非常困难。所以我就做了这个。

支持

Swift 3.0 & iOS 8+

安装

使用CocoaPods

  • 将其添加到Podfile文件中。
pod 'CuteAttribute'
  • 然后运行以下命令。
pod install
  • 在项目中导入头文件。
import CuteAttribute

使用Carthage

  • 将CuteAttribute添加到Cartfile中。
github "qiuncheng/CuteAttribute"
  • 运行以下命令
carthage update --platform ios
import CuteAttribute

手动安装

用法

比较

属性名称 结果 NSAttributedString CuteAttribute
颜色 NSMutableAttributedString(string: "hello world", attributes: [.foregroundColor: UIColor.red]) "hello world".cute.matchAll().color(.red)
基线偏移量 NSMutableAttributedString(string: "hello world", attributes: [.baselineOffset: 10]) "hello world".cute.matchAll().baseline(10)
下划线 NSMutableAttributedString(string: "hello world", attributes: [.underlineColor: UIColor.red, .underlineStyle: NSUnderlineStyle.styleSingle.rawValue]) "hello world".cute.matchAll().underline(.styleSingle).underlineColor(.red)
字体 NSMutableAttributedString(string: "hello world", attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20)]) "hello world".cute.matchAll().font(UIFont.systemFont(ofSize: 20))
删除线 NSMutableAttributedString(string: "hello world", attributes: [.strikethroughStyle: NSUnderlineStyle.styleSingle.rawValue, .strikethroughColor: UIColor.red]) "hello world".cute.matchAll().strikeThrough(.styleSingle).strokeColor(.red)
链接 NSMutableAttributedString(string: "hello world", attributes: [.link: "https://blog.vsccw.com"]) "hello world".cute.matchAll().link("https://blog.vsccw.com")
连字符 NSMutableAttributedString(string: "hello world", attributes: [.ligature: 1]) "hello world".cute.matchAll().ligature(1)
字距调整 NSMutableAttributedString(string: "hello world", attributes: [.kern: 10]) "hello world".cute.matchAll().kern(10)
描边 NSMutableAttributedString(string: "hello world", attributes: [.strokeColor: UIColor.red, .strokeWidth: 10]) "hello world".cute.matchAll().strokeColor(.red).strokeWidth(10)
阴影 let shadow = NSShadow(); shadow.shadowColor = UIColor.red; shadow.shadowOffset = CGSize(width: 4, height: 4); shadow.shadowBlurRadius = 10; NSMutableAttributedString(string: "hello world", attributes: [.shadow: shadow]) "hello world".cute.matchAll().shadow(shadow)
文字特效 no image "hello world".cute.matchAll().textEffect("NSTextEffectLetterpressStyle") "hello world".cute.matchAll().textEffect("NSTextEffectLetterpressStyle")
倾斜度 NSMutableAttributedString(string: "hello world", attributes: [.obliqueness: 10]) "hello world".cute.matchAll().obliqueness(10)
膨胀 NSMutableAttributedString(string: "hello world", attributes: [.expansion: 10]) "hello world".cute.matchAll().expansion(10)
文字附加 let attachment = NSTextAttachment(); attachment.image = UIImage(named: "hello.png"); NSMutableAttributedString(string: "hello world", attributes: [.attachment: attachment]) "hello world".cute.matchAll().textAttachment(attachment)

待办事项

  • 已记录。
  • 示例。
  • 测试。
  • 更多便利。

感谢

排版 : 高效地处理 Objective-C 中的 AttributedString。

许可

MIT 许可下