NSAttributedString creation with Swift 5 string interpolation
let swiftLogo = UIImage(named: "SwiftLogo")!
let url = URL(string: "https://swift.org/")!
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))")
Add this to your project using Swift Package Manager. In Xcode that is simply: File > Swift Packages > Add Package Dependency... and you're done.
dependencies: [
.package(url: "https://github.com/koznobikhin/OzStringKit.git", .upToNextMajor(from: "0.0.8"))
]
Accio is a dependency manager based on SwiftPM which can build frameworks for iOS/macOS/tvOS/watchOS. Therefore the integration steps of OzStringKit are exactly the same as described above. Once your Package.swift
file is configured, run accio update
instead of swift package update
.
If you are already using CocoaPods, just add 'OzStringKit' to your Podfile
then run pod install
.
For more detailed usage and installation instructions, visit their website.
pod 'OzStringKit'
Konstantin Oznobikhin
OzStringKit is available under the MIT license. See the LICENSE file for more information.