SwiftyAttributedString 1.0.1

SwiftyAttributedString 1.0.1

Yuto Akibatouyu 维护。



  • touyu

Swift 3.0.2 Platform CocoaPods compatible Carthage compatible License

功能

  • 舒适的 NSAttributedString
  • 更好的自动补全
  • 简单的范围指定
  • 可链式方法

安装

Carthage

将以下行添加到 Cartfile 中

github "touyu/SwiftyAttributedString"

创建框架

$ carthage update --platform iOS

CocoaPods

将以下行添加到 Podfile 中

pod 'SwiftyAttributedString'

在终端中输入以下命令

$ pod install

示例

textView.attributedText = "SwiftyAttributedString"
        .attr
        .font(.systemFont(ofSize: 30))
        .range(of: "Swifty") {
            $0.foregroundColor(.blue)
        }
        .range(of: "Attributed") {
            $0.foregroundColor(.red)
            $0.underlineStyle(.single)
        }
        .range(of: "String") {
            $0.foregroundColor(.orange)
            $0.font(.boldSystemFont(ofSize: 30))
        }
        .apply()

文档

所有范围

"SwiftyAttributedString"
         .attr
         .font(.systemFont(ofSize: 30)) // All range
         .apply()
  

特定范围

"SwiftyAttributedString"
         .attr
         .range(start: 0, end: 3) {
              font(.systemFont(ofSize: 30)) // The specific range
         }
         .apply()