Helps you manage text styles in your app.
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())
}
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)
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.
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"