OzStringKit 0.0.8

OzStringKit 0.0.8

Konstantin Oznobikhin 维护。




  • Konstantin Oznobikhin

OzStringKit

Travis (.com) GitHub tag (latest SemVer) Accio supported Swift Package Manager compatible Cocoapods Platforms License

使用 Swift 5 字符串插值创建 NSAttributedString

示例

let swiftLogo = UIImage(named: "SwiftLogo")!
let url = URL(string: "https://swiftlang.cn/")!

let attributedText = attributedString("""
    \("Some colorful text:", .underline(.single, color: .red))
    \("red", .color(.red)), \("orange", .color(.orange)), \("yellow", .color(.yellow)), \
    \("green", .color(.green)), \("blue", .color(.blue))

    \(image: swiftLogo) an image and an \("url", .link(url))
    """)

let shadow = NSShadow()
shadow.shadowColor = UIColor.black.withAlphaComponent(0.3)
shadow.shadowBlurRadius = 4.0
shadow.shadowOffset = CGSize(width: 0.0, height: 2.0)
self.label.attributedText = attributedString("\(attributedText, .alignment(.center), .shadow(shadow))")

Screen shot

安装

Swift 包管理器

使用 Swift 包管理器将此添加到你的项目。在 Xcode 中,这很简单:文件 > Swift 包 > 添加包依赖... 就完成了。

dependencies: [
    .package(url: "https://github.com/koznobikhin/OzStringKit.git", .upToNextMajor(from: "0.0.8"))
]

Accio

Accio 是一个基于 SwiftPM 的依赖管理器,可以为 iOS/macOS/tvOS/watchOS 构建框架。因此,OzStringKit 的集成步骤与上述描述完全一样。一旦你的 Package.swift 文件配置完毕,请运行 accio update 而不是 swift package update

CocoaPods

如果您已经使用 CocoaPods,只需将'奥兹字符串工具'添加到您的 Podfile,然后运行 pod install。有关更详细的用法和安装说明,请访问他们的网站。

pod 'OzStringKit'

作者

Konstantin Oznobikhin

许可

奥兹字符串工具遵循MIT许可协议。更多信息请查看LICENSE文件