Skip to content

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

License

Notifications You must be signed in to change notification settings

janeshgupta/SwiftyAttributes

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftyAttributes

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

The original way to create an attributed string in Swift:

let attributes: [String: AnyObject] = 
	[NSForegroundColorAttributeName: UIColor.blueColor(), 
     NSUnderlineStyleAttributeName:  NSNumber(integer: 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(UIColor.blueColor()).withUnderlineStyle(.StyleSingle)

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

let fancyString = "Hello".withFont(UIFont.systemFontOfSize(12)) + " World!".withFont(UIFont.systemFontOfSize(18))

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

Installation

With CocoaPods:

pod 'SwiftyAttributes'

Manually:

Download the zip file (or clone the project), and drag SwiftyAttributes.swift into your project.

Contact

Eddie Kaiger

License

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 96.1%
  • Ruby 3.9%