Skip to content

trafi/TextStyle

Repository files navigation

Swift Package Manager compatible Carthage compatible

TextStyle

Helps you manage text styles in your app.

Describing text styles

Extend TextStyle with static variables for different text styles used in your app:

extension TextStyle {
    static let header = TextStyle()
        .with(font: .boldSystemFontOfSize(18))
        .with(color: .redColor())
        .with(alignment: .Center)
    
    static let body = TextStyle()
        .with(font: .systemFontOfSize(16))
    
    static let footer = TextStyle()
        .with(font: .italicSystemFontOfSize(12))
        .with(color: .grayColor())
}

Usage

From code

There's a set(textStyle:) defined for text-based UI elements. Just call it providing one of your styles.

let titleLabel = UILabel()
titleLabel.set(textStyle: .header)

From Interface Builder

Extend TextStyle conforming to IBInspectable protocol:

extension TextStyle: IBInspectable {
    static var stylesDictionary: [String : TextStyle] {
        return [
            "header": .header,
            "body":   .body,
            "footer": .footer
        ]
    }
}

In the Interface Builder set Text Style to match your style's name.

To see style changes right in the Interface Builder use Designable UI elements classes. (i.e. UILabelDesignable). You should and add them to your project manually.

Installation

Open your project in Xcode and select File > Swift Packages > Add Package Dependency. There enter https://github.com/trafi/TextStyle as the repository URL.

Add the following line to your Cartfile:

github "Trafi/TextStyle"

About

Helps you manage text styles in your app

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages