TypographyKit makes it easy to define typography styles and colour palettes in your iOS app helping you achieve visual consistency in your design as well as supporting Dynamic Type even when using custom fonts. [Summary][Detailed]
To learn more about how to use TypographyKit, take a look at the table of contents below:
Helps keep your app visually consistent across all screens by allowing you to define all of your typography styles and app color scheme in a single location.
Host and update your font styles and color schemes remotely. [Details]
Dynamic Type support for UIKit (including UILabel, UIButton, UITextField and UITextView as well as some support for NSAttributedString).
Support for Dynamic Type using zero code (by setting the fontTextStyleName key path String to the name of your typography style in Interface Builder).
Use either JSON or Property List (.plist) to define your TypographyKit configuration.
Use Palette to make the same colour scheme used programmatically available for use in Interface Builder. [Details]
First-class support for SwiftUI colors - to obtain a color, use TK.color(named:).
You may specify a fallback color to be used in the event that you forget to define a color. Use the fallback-color key to specify which color should be used in this case.
Setting: fallback-color
Default: Black in light mode and white in dark mode.
You may specify a development color which is used in the event that you forget to define a color in development builds. This color may be different from the fallback color. For example, you may want to use an easily noticeable color such as red to make it visually clear that you have forgotten to define a color in development builds. However, you may want to ensure that this red color will never be shown in production builds - this is why development colors will never be shown in production builds (instead the fallback color will be used).
Setting: development-color
Default: red
Setting: is-development
Default: true in #DEBUG builds; false otherwise
Setting: should-use-development-colors
Default: true
You may optionally specify that your development app builds crash if you forget to define a color. This makes it even less likely that you will forget to specify a color value during development. This setting only affects development builds so there is no need to worry that production builds might crash.
Setting: should-crash-if-color-not-found
Default: false
To start using the framework, now import TypographyKit and then configure as follows:
Carthage is a dependency manager which produces a binary for manual integration into your project. It can be installed via Homebrew using the commands:
brew update
brew install carthage
In order to integrate TypographyKit into your project via Carthage, add the following line to your project’s Cartfile:
github "rwbutler/TypographyKit"
From the macOS Terminal run carthage update --platform iOS to build the framework then drag TypographyKit.framework into your Xcode project.
An example app exists in the Example directory to provide some pointers on getting started.
Configuration
Include a TypographyKit.json (example) or TypographyKit.plist (example) as part of your app project in which you define your colors and typography styles:
Or where your text has been set through IB simply set the UIFont.TextStyle programmatically:
self.titleLabel.fontTextStyle = .heading
If you are happy to use strings, an alternative means of setting the fontTextStyle property is to set the key path fontTextStyleName on your UIKit element to the string value representing your fontTextStyle - in the example above, this would be ‘heading’.
Using this method it is possible to support Dynamic Type in your application with zero code.
Your UILabel and UIButton elements will automatically respond to changes in the Dynamic Type setting on iOS on setting a UIFont.TextStyle with no further work needed.
Typography Styles
Typography styles you define in TypographyKit.plist can optionally include a text color and a letter case.
From version 1.1.3 onwards it is possible to use an existing typography style to create a new one. For example, imagine you would like to create a new style based on an existing one but changing the text color. We can use the extends keyword to extend a style that exists already and then specify which properties of the that style to override e.g. the text-color property.
We can create a new typography style called interactive-text based on a style we have defined already called paragraph as follows:
Android has from the start provided developers with the means to define a color palette for an app in the form of the colors.xml file. Colors.xml also allows developers to define colors by their hex values. TypographyKit allows developers to define a color palette for an app by creating an entry in the TypographyKit.plist.
TypographyKit supports definition of colors via asset catalogs. Simply include the name of the color as part of your style in the configuration file and if the color is found in your asset catalog it will automatically be applied.
Letter Casing
Useful String additions are provided to easily convert letter case.
let pangram = "The quick brown fox jumps over the lazy dog"
let upperCamelCased = pangram.letterCase(.upperCamel)
print(upperCamelCased)
// prints TheQuickBrownFoxJumpsOverTheLazyDog
With numerous convenience functions:
let upperCamelCased = pangram.upperCamelCased()
// prints TheQuickBrownFoxJumpsOverTheLazyDog
let kebabCased = pangram.kebabCased()
// prints the-quick-brown-fox-jumps-over-the-lazy-dog
Typography styles can be assigned a default letter casing.
By default, your font point size will increase by 2 points for each notch on the Larger Text slider in the iOS accessibility settings however you may optionally specify how your UIKit elements react to changes in UIContentSizeCategory.
You may specify your own point step size and multiplier by inclusion of a dictionary with key typography-kit as part of your TypographyKit.json (or TypographyKit.plist if preferred) file.
Optionally, you may clamp the font point size to a lower and / or upper bound using the minimum-point-size and maximum-point-size properties.
Remote Configuration
TypographyKit also allows you to host your configuration remotely so that your colors and font styles can be updated dynamically. To do so, simply add the following line to your app delegate so that it is invoked when your app finishes launching:
Your typography styles and colors will be updated the next time your app is launched. However, should you need your styles to be updated sooner you may call TypographyKit.refresh().
Connectivity - Improves on Reachability for determining Internet connectivity in your iOS application.
FeatureFlags - Allows developers to configure feature flags, run multiple A/B or MVT tests using a bundled / remotely-hosted JSON configuration file.
FlexibleRowHeightGridLayout - A UICollectionView grid layout designed to support Dynamic Type by allowing the height of each row to size to fit content.
Hash - Lightweight means of generating message digests and HMACs using popular hash functions including MD5, SHA-1, SHA-256.
Skylark - Fully Swift BDD testing framework for writing Cucumber scenarios using Gherkin syntax.
TailorSwift - A collection of useful Swift Core Library / Foundation framework extensions.
TypographyKit - Consistent & accessible visual styling on iOS with Dynamic Type support.
Updates - Automatically detects app updates and gently prompts users to update.
TypographyKit makes it easy to define typography styles and colour palettes in your iOS app helping you achieve visual consistency in your design as well as supporting Dynamic Type even when using custom fonts. [Summary] [Detailed]
To learn more about how to use TypographyKit, take a look at the table of contents below:
Features
fontTextStyleName
key path String to the name of your typography style in Interface Builder).What’s new in TypographyKit 5.0.0?
First-class support for SwiftUI colors - to obtain a color, use
TK.color(named:)
.You may specify a fallback color to be used in the event that you forget to define a color. Use the
fallback-color
key to specify which color should be used in this case.fallback-color
You may specify a development color which is used in the event that you forget to define a color in development builds. This color may be different from the fallback color. For example, you may want to use an easily noticeable color such as red to make it visually clear that you have forgotten to define a color in development builds. However, you may want to ensure that this red color will never be shown in production builds - this is why development colors will never be shown in production builds (instead the fallback color will be used).
development-color
red
is-development
true
in #DEBUG builds;false
otherwiseshould-use-development-colors
true
You may optionally specify that your development app builds crash if you forget to define a color. This makes it even less likely that you will forget to specify a color value during development. This setting only affects development builds so there is no need to worry that production builds might crash.
should-crash-if-color-not-found
false
To start using the framework, now
import TypographyKit
and then configure as follows:Alternatively, an
async
version of this method exists for developers supporting iOS 13 and above:For a detailed list of changes, see CHANGELOG.md.
Installation
Cocoapods
CocoaPods is a dependency manager which integrates dependencies into your Xcode workspace. To install it using RubyGems run:
To install TypographyKit using Cocoapods, simply add the following line to your Podfile:
Then run the command:
For more information see here.
Carthage
Carthage is a dependency manager which produces a binary for manual integration into your project. It can be installed via Homebrew using the commands:
In order to integrate TypographyKit into your project via Carthage, add the following line to your project’s Cartfile:
From the macOS Terminal run
carthage update --platform iOS
to build the framework then dragTypographyKit.framework
into your Xcode project.For more information see here.
Usage
Example App
An example app exists in the Example directory to provide some pointers on getting started.
Configuration
Include a TypographyKit.json (example) or TypographyKit.plist (example) as part of your app project in which you define your colors and typography styles:
Swift UI
Colors
Typography (Fonts)
Define additional UIFont.TextStyles within your app matching those defined in your .plist:
Where you would usually set the text on a UILabel e.g.
Use TypographyKit’s UIKit additions:
Or where your text has been set through IB simply set the UIFont.TextStyle programmatically:
If you are happy to use strings, an alternative means of setting the
fontTextStyle
property is to set the key pathfontTextStyleName
on your UIKit element to the string value representing your fontTextStyle - in the example above, this would be ‘heading’.Using this method it is possible to support Dynamic Type in your application with zero code.
Your UILabel and UIButton elements will automatically respond to changes in the Dynamic Type setting on iOS on setting a UIFont.TextStyle with no further work needed.
Typography Styles
Typography styles you define in TypographyKit.plist can optionally include a text color and a letter case.
Extending Styles
From version 1.1.3 onwards it is possible to use an existing typography style to create a new one. For example, imagine you would like to create a new style based on an existing one but changing the text color. We can use the
extends
keyword to extend a style that exists already and then specify which properties of the that style to override e.g. thetext-color
property.We can create a new typography style called
interactive-text
based on a style we have defined already calledparagraph
as follows:PLIST
JSON
Color Palettes
Android has from the start provided developers with the means to define a color palette for an app in the form of the colors.xml file. Colors.xml also allows developers to define colors by their hex values. TypographyKit allows developers to define a color palette for an app by creating an entry in the TypographyKit.plist.
Colors can be defined using hex values, RGB values or simple colors by using their names e.g. ‘blue’.
Create a UIColor extension to use the newly-defined colors throughout your app:
Or:
Your named colors can be used when defining your typography styles in TypographyKit.plist.
It is also possible override the text color of a typography style on a case-by-case basis:
UIColor(named:)
TypographyKit supports definition of colors via asset catalogs. Simply include the name of the color as part of your style in the configuration file and if the color is found in your asset catalog it will automatically be applied.
Letter Casing
Useful String additions are provided to easily convert letter case.
With numerous convenience functions:
Typography styles can be assigned a default letter casing.
However occasionally, you may need to override the default letter casing of a typography style:
Dynamic Type Configuration
By default, your font point size will increase by 2 points for each notch on the Larger Text slider in the iOS accessibility settings however you may optionally specify how your UIKit elements react to changes in UIContentSizeCategory.
You may specify your own point step size and multiplier by inclusion of a dictionary with key
typography-kit
as part of yourTypographyKit.json
(orTypographyKit.plist
if preferred) file.Optionally, you may clamp the font point size to a lower and / or upper bound using the
minimum-point-size
andmaximum-point-size
properties.Remote Configuration
TypographyKit also allows you to host your configuration remotely so that your colors and font styles can be updated dynamically. To do so, simply add the following line to your app delegate so that it is invoked when your app finishes launching:
Your typography styles and colors will be updated the next time your app is launched. However, should you need your styles to be updated sooner you may call
TypographyKit.refresh()
.Author
Ross Butler
License
TypographyKit is available under the MIT license. See the LICENSE file for more info.
Additional Software
Controls
Frameworks
Tools
cdd
from the Terminal.