SwiftyAttributes travis-ci ruby CocoaPods

Swift extensions that make it a breeze to work with attributed strings.

SwiftyAttributes

Swift extensions that make it a breeze to work with attributed strings.

Swift Version Carthage compatible CocoaPods Compatible Platform Travis CI codecov.io


The original way to create an attributed string in Swift:

let attributes: [String: AnyObject] = [
    NSForegroundColorAttributeName: UIColor.blue, 
    NSUnderlineStyleAttributeName:  NSNumber(value: NSUnderlineStyle.styleSingle.rawValue)
]
let fancyString = NSAttributedString(string: "Hello World!", attributes: attributes) 

With SwiftyAttributes, you can write the same thing like this:

let fancyString = "Hello World!".withTextColor(.blue).withUnderlineStyle(.styleSingle)

You can also easily combine attributed strings using a plus sign:

let fancyString = "Hello".withFont(.systemFont(ofSize: 12)) + " World!".withFont(.systemFont(ofSize: 18))

SwiftyAttributes Has support for every attribute that can be used in iOS.

Requirements

  • iOS 9.0+

Installation

With CocoaPods

For Swift 3:

pod 'SwiftyAttributes'

For Swift 2.3:

pod 'SwiftyAttributes', '1.1'

If using Xcode 8, you may need to add this to end of your Podfile:

post_install do |installer|
    installer.pods_project.targets.each do |target| 
        target.build_configurations.each do |config| 
            config.build_settings["SWIFT_VERSION"] = "2.3"
        end
    end
end

With Carthage

For Swift 3:

github "eddiekaiger/SwiftyAttributes"

For Swift 2.3:

github "eddiekaiger/SwiftyAttributes" == 1.1.1

The Future

The future of SwiftyAttributes will consist of creating a fully-featured, type-safe, Swifty API for all use cases of attributed strings. Version 2.1 will bring about some basic, much-needed features such as adding attributes using a range. The goal of version 3.0 will be full support for macOS, tvOS, and watchOS, as well as a wider range of capabilities.

If you have suggestions and feature requests, please feel free to open up an issue.

Support

For questions and support, please open up an issue.

License

SwiftyAttributes is available under the MIT license. See the LICENSE file for more info.

Related Repositories

SwiftyAttributes

SwiftyAttributes

Swift extensions that make it a breeze to work with attributed strings. ...


Top Contributors

eddiekaiger Latyntsev BasThomas

Releases

-   v2.0.2 zip tar
-   v2.0.1 zip tar
-   v2.0 zip tar
-   v1.1.1 zip tar
-   v1.1 zip tar
-   v1.0 zip tar