πŸ“° Consistent & accessible visual styling on iOS with support for Dynamic Type.

Overview

TypographyKit

Build Status Version Carthage compatible License Platform Twitter Swift 5.0 Reviewed by Hound

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

  • Dynamic Type support for UILabel, UIButton, UITextField and UITextView as well as some support for NSAttributedString.
  • Dynamic Type support for SwiftUI.
  • Dynamic Type support for custom fonts prior to iOS 11 (iOS 8 onwards).
  • Optionally support Dynamic Type using zero code (by setting the fontTextStyleName key path String to the name of your typography style in IB).
  • Helps make your app visually consistent across all screen 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]
  • Use Palette to make the same colour scheme used programmatically available for use in Interface Builder. [Details]
  • Define letter case as part of typography styles with simple letter case conversion available.
  • Use either a PList or JSON to define your TypographyKit configuration.

What's new in TypographyKit 4.0.0?

TypographyKit 4.0.0 introduces support for SwiftUI. In order to make use of TypographyKit with SwiftUI, create a TypographyKit configuration file (either JSON or PList) and an extension on UIFont.TextStyle as described in the Usage section, then simply apply your typography style to a SwiftUI Text view as follows:

Text("An example using TypographyKit with SwiftUI")
.typography(style: .interactive)

A letter case may be applied directly to the String as follows:

"An example using TypographyKit with SwiftUI"
.letterCase(style: .interactive)

This results in the letter case defined for the specified typography style (in config) being applied.

What's new in TypographyKit 3.0.0?

TypographyKit 3.0.0 supports Xcode 11 and dark mode in iOS 13 and supports iOS 8.2 and above. The last version supporting Xcode 10 and targeting the iOS 12 SDK is version 2.2.3.

TypographyKit 2.0.0 brings support for Swift 5.0. The previous version supporting Swift 4.2 is version 1.1.5.

If you require the Swift 4.2 version then in your Podfile:

pod "TypographyKit" "~> 1.1.5" 

Or if you are using Carthage add the following to your Cartfile:

github "rwbutler/TypographyKit" ~> 1.1.5

In TypographyKit 1.1.5 is now possible to reference the system font or system font and weight as part of your configuration by setting the font-name property value to System or e.g. System-Bold to additionally specify the font weight.

It is now possible to use UIFontMetrics to scale fonts where iOS 11 is available and using the system-provided UIFont.TextStyle options only by setting the scaling-mode property in the configuration file. Allowable values include stepping (default behavior), uifontmetrics and uifontmetrics-with-fallback. See CHANGELOG.md.

Installation

Cocoapods

CocoaPods is a dependency manager which integrates dependencies into your Xcode workspace. To install it using RubyGems run:

gem install cocoapods

To install TypographyKit using Cocoapods, simply add the following line to your Podfile:

pod "TypographyKit"

Then run the command:

pod install

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:

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.

For more information see here.

Example App

An example app exists in the Example directory to provide some pointers on getting started.

Usage

Include a TypographyKit.plist as part of your app project (example) in which you define your typography styles.

	<key>ui-font-text-styles</key>
	<dict>
		<key>heading</key>
		<dict>
			<key>font-name</key>
			<string>Avenir-Medium</string>
			<key>point-size</key>
			<integer>36</integer>
		</dict>
	</dict>

Or if you prefer to use JSON you may include a TypographyKit.json (example) instead.

Define additional UIFont.TextStyles within your app matching those defined in your .plist:

extension UIFont.TextStyle
{
    static let heading = UIFont.TextStyle(rawValue: "heading")
}

Where you would usually set the text on a UILabel e.g.

self.titleLabel.text = "My label text"

Use TypographyKit's UIKit additions:

self.titleLabel.text("My label text", style: .heading)

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'.

Setting the fontTextStyleName key path in Interface Builder

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.

	<key>ui-font-text-styles</key>
	<dict>
		<key>heading</key>
		<dict>
			<key>font-name</key>
			<string>Avenir-Medium</string>
			<key>point-size</key>
			<integer>36</integer>
			<key>text-color</key>
			<string>#2C0E8C</string>
			<key>letter-case</key>
			<string>upper</string>
		</dict>
	</dict>

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. 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:

PLIST

<key>paragraph</key>
<dict>
	<key>font-name</key>
	<string>Avenir-Medium</string>
	<key>point-size</key>
	<integer>16</integer>
	<key>text-color</key>
	<string>text</string>
	<key>letter-case</key>
	<string>regular</string>
</dict>
<key>interactive-text</key>
<dict>
	<key>extends</key>
	<string>paragraph</string>
	<key>text-color</key>
	<string>purple</string>
</dict>

JSON

"paragraph": {
	"font-name": "Avenir-Medium",
	"point-size": 16,
	"text-color": "text",
	"letter-case": "regular"
},
"interactive-text": {
	"extends": "paragraph",
	"text-color": "purple"
}        

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.

    <key>typography-colors</key>
    <dict>
        <key>blueGem</key>
        <string>#2C0E8C</string>
    </dict>

Colors can be defined using hex values, RGB values or simple colors by using their names e.g. 'blue'.

	<key>typography-colors</key>
    <dict>
        <key>blueGem</key>
        <string>rgb(44, 14, 140)</string>
    </dict>

Create a UIColor extension to use the newly-defined colors throughout your app:

extension UIColor {
    static let blueGem: UIColor = TypographyKit.colors["blueGem"]!
}

Or:

extension UIColor {
	static let fallback: UIColor = .black
	static let blueGem: UIColor = TypographyKit.colors["blueGem"] ?? fallback
}

Your named colors can be used when defining your typography styles in TypographyKit.plist.

 	<key>ui-font-text-styles</key>
	<dict>
		<key>heading</key>
		<dict>
			<key>font-name</key>
			<string>Avenir-Medium</string>
			<key>point-size</key>
			<integer>36</integer>
			<key>text-color</key>
			<string>blueGem</string>
		</dict>
	</dict>

It is also possible override the text color of a typography style on a case-by-case basis:

myLabel.text("hello world", style: .heading, textColor: .blue)

UIColor(named:)

TypographyKit also supports definition of colors via asset catalogs available from iOS 11 onwards. 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.

	<key>ui-font-text-styles</key>
	<dict>
		<key>heading</key>
		<dict>
			<key>font-name</key>
			<string>Avenir-Medium</string>
			<key>point-size</key>
			<integer>36</integer>
			<key>letter-case</key>
			<string>upper</string>
		</dict>
	</dict>

However occasionally, you may need to override the default letter casing of a typography style:

myLabel.text("hello world", style: .heading, letterCase: .capitalized)

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 your TypographyKit.plist file.

<key>typography-kit</key>
<dict>
    <key>minimum-point-size</key>
    <integer>10</integer>
    <key>maximum-point-size</key>
    <integer>100</integer>
    <key>point-step-size</key>
    <integer>2</integer>
    <key>point-step-multiplier</key>
    <integer>1</integer>
</dict>

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:

TypographyKit.configurationURL = URL(string: "https://github.com/rwbutler/TypographyKit/blob/master/Example/TypographyKit/TypographyKit.plist")

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

AnimatedGradientView
AnimatedGradientView

Frameworks

  • Cheats - Retro cheat codes for modern iOS apps.
  • 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.
Cheats Connectivity FeatureFlags Skylark TypographyKit Updates
Cheats Connectivity FeatureFlags Skylark TypographyKit Updates

Tools

  • Clear DerivedData - Utility to quickly clear your DerivedData directory simply by typing cdd from the Terminal.
  • Config Validator - Config Validator validates & uploads your configuration files and cache clears your CDN as part of your CI process.
  • IPA Uploader - Uploads your apps to TestFlight & App Store.
  • Palette - Makes your TypographyKit color palette available in Xcode Interface Builder.
Config Validator IPA Uploader Palette
Config Validator IPA Uploader Palette
Comments
  • Setting preferredContentSizeCategory in app

    Setting preferredContentSizeCategory in app

    Im looking into using TypographyKit and I looks very promising to get our typography organised, right now it's a mess.

    One thing I'm not sure how to do though is this:

    We need our end-users to be able to se the preferredContentSizeCategory directly in the app (hence overriding the setting from Settings.app) og choose the not override and just go with their system setting.

    I did a quick test with TypographyKit where I am setting the overriding preferredContentSizeCategory by subclassing UIApplication like so:

    class App: UIApplication{
        
        var customSize: UIContentSizeCategory?
        
        override var preferredContentSizeCategory: UIContentSizeCategory{
            return size ?? super.preferredContentSizeCategory
        }
        
    }
    

    This does kinda work, but I was unable to get TypographyKit to refresh the sizes when setting customSize (with out persisting the setting and restarting the app). Is there a way to force TypographyKit to update all text but fetching the new UIContentSizeCategory? I tried calling TypographyKit.refresh() but this seems to fetch new configuration now apply the new UIContentSizeCategory.

    Hopefully someone will be able to help with this as this is the last thing I'm missing to start using TypographyKit

    enhancement help wanted 
    opened by icedice 7
  • Support for disabled-text-color, highlighted-text-color and selected-text-color

    Support for disabled-text-color, highlighted-text-color and selected-text-color

    Hello!

    I noticed TypographyKit overrides in UIButtonAdditions.swift whatever title colors we have defined in IB/when setting up the button in code. To that end I added support for three new properties that apply to UIButtons only: disabled-text-color, highlighted-text-color and selected-text-color. If defined, they will be applied, if not, we will fall back to the current behavior.

    I also added support for applying these extra properties for NSAttributedStrings and updated the README.md. Would be nice to see this in the main repo, I don't believe it has any drawbacks.

    Thanks!

    opened by alinradut 3
  • Can disable scaling and specify letter spacing as font attribute.

    Can disable scaling and specify letter spacing as font attribute.

    * Added case to ScaleMode enum to optionally disable font scaling.
    * If scale mode is set to .disabled, the requested font is resolved at the size given in the config.
    * Added letter-spacing as typography plist attribute for font styles. Defaults to zero.
    * UILabel.text() checks self.typography.letterSpacing > 0, and if true, converts text to attributed string and calls its attributedText method.
    
    opened by jacob-jennings 2
  • Feature: able to use synonym using fonts name

    Feature: able to use synonym using fonts name

    Motivation: In a project, might have 7 basic font size like: title1, title2, title3, body etc. I would like to define logical fonts name that will "inherit" the basic font. like: button -> title2 + blackColor imageCaptions -> body + other feature

    Suggestion: "title2": { "font-name": "NotoSans-Regular", "point-size":19, "text-color": "white" }, "button": { "basedOn":"title2", "text-color": "yellow" },

    enhancement 
    opened by wishtrip-dev 2
  • Is it possible to have multiple configuration files in app?

    Is it possible to have multiple configuration files in app?

    Is it possible to have multiple configuration files in app? I'm using version 1.1.5 with iOS 11.4 I tried to assign new configuration plist file (with different name in resources) and tried do Typography.refresh() but it has no effect The reason is to split configuration between several views keeping only necessary settings Thanks

    opened by vitt0re 1
  • Remove SwiftUI modifiers when values are nil

    Remove SwiftUI modifiers when values are nil

    This fixes an issue where applying a modifier for a typography style with no specified color in TypographyKit will prevent another color .foregroundColor(.green) taking effect when chained on a view.

    Example

    typography-kit.json

    "ui-font-text-styles": {
            "heading": {
                "font-name": "SomeFont",
                "point-size": 30,
                "letter-case": "regular"
            }
    }
    

    code:

     Text("This text should be green") 
                .typography(style: .heading)
                .foregroundColor(.green)
    

    Existing result:

    Text appears default color

     Text("This text should be green") 
                .font(SomeFont)
                .foregroundColor(nil)
                .foregroundColor(.green)
    

    Fixed result:

    Text appears green

     Text("This text should be green") 
                .font(SomeFont) 
                .foregroundColor(.green)
    
    opened by roger-smith 0
  • Fix minimum size limits for system fonts when using UIFontMetrics

    Fix minimum size limits for system fonts when using UIFontMetrics

    Incorrect font was returned when scaled point size was below minimum point size. Warning in console: Client requested name ".SFUI-Bold", it will get TimesNewRomanPSMT rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[UIFont systemFontOfSize:].

    opened by roger-smith 0
Releases(4.4.0)
  • 4.4.0(Aug 17, 2022)

    [4.4.0] - 2022-08-16

    Changed

    • When using the View modifier in SwiftUI, the scaling mode can be specified as a parameter e.g. .typography(style: .interactive, scalingMode: .fontMetrics). By default the scaling mode specified in the configuration will be applied.
    Source code(tar.gz)
    Source code(zip)
  • 4.3.2(Mar 16, 2022)

  • 4.3.1(Nov 9, 2021)

  • 4.3.0(Nov 9, 2021)

    [4.3.0] - 2021-11-09

    Added

    • Support for disabling font scaling either system-wide and/or per-font.
    • Support for custom letter spacing in font styles plist.

    Credit to @jacob-jennings and @Loadex for this.

    Source code(tar.gz)
    Source code(zip)
  • 4.2.2(Dec 16, 2020)

  • 4.2.1(Aug 4, 2020)

    Changed

    Fixes support for Swift Package Manager by making TypographyKitViewController and TypographyKitColorsViewController programmatic over using storyboards & xibs.

    Source code(tar.gz)
    Source code(zip)
  • 1.1.1(Mar 15, 2019)

    Added

    • Added refreshWithData(_:) for refreshing configuration data from a configuration file which has already been downloaded.

    Changed

    • After updating the configurationURL property, configuration is reloaded from the new URL.
    • Prioritizes JSON configuration files over property lists should both exist in an app's bundle.
    Source code(tar.gz)
    Source code(zip)
  • 0.4.4(Sep 11, 2018)

    Invoking TypographyKit.presentTypographyStyles() will now present a TypographyKitViewController modally for listing all the typography styles in your app with an option to export to PDF.

    Source code(tar.gz)
    Source code(zip)
  • 0.4.3(Sep 9, 2018)

  • 0.4.2(Sep 7, 2018)

    Allows the font point size to be clamped to a lower and / or upper bound by optionally defining the minimum-point-size / maximum-point-size in the TypographyKit configuration file.

    Source code(tar.gz)
    Source code(zip)
  • 0.4.1(Jul 27, 2018)

    This release introduces support for integration using the Carthage dependency manager. In order to integrate TypographyKit into your project via Carthage, add the following line to your project's Cartfile:

    github "rwbutler/TypographyKit"

    This release is unavailable through Cocoapods as it introduces no functional changes from the previous release for developers who have already integrated v0.4.0.

    Source code(tar.gz)
    Source code(zip)
  • 0.4.0(Jul 23, 2018)

    Support for recursive color definitions and obtaining lighter / darker shades of colors.

    Blog post: https://medium.com/@rwbutler/remotely-configured-colour-palettes-in-typographykit-e565c927e2b4

    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Jul 5, 2018)

Owner
Ross Butler
πŸ“± Apps Engineering Manager
Ross Butler
Powerful and easy-to-use vector graphics Swift library with SVG support

Macaw Powerful and easy-to-use vector graphics Swift library with SVG support We are a development agency building phenomenal apps. What is Macaw? Mac

Exyte 5.9k Jan 2, 2023
The code for my CoreGraphics+CoreAnimation talk, held during the 2012 iOS Game Design Seminar at the Technical University Munich.

PKCoreTechniques ======= Core Techniques is the result of a presentation I held at the Technical University of Munich during the 'iOS Game Design Semi

Philip Kluz 143 Sep 21, 2022
Drawing and Geometry made easy on iOS - now in Swift 3.0

InkKit Swift Support Swift 4.0 InkKit is Swift 4.0 by default, so to use that just include InkKit in your podfile: pod 'InkKit' Swift 3.2 In order to

Shaps 373 Dec 27, 2022
iOS utility classes for asynchronous rendering and display.

YYAsyncLayer iOS utility classes for asynchronous rendering and display. (It was used by YYText) Simple Usage @interface YYLabel : UIView @property NS

null 672 Dec 27, 2022
An iOS framework for easily adding drawings and text to images.

jot is an easy way to add touch-controlled drawings and text to images in your iOS app. What's jot for? Annotating Images jot is the easiest way to ad

IFTTT 1.8k Oct 28, 2022
Display and interact with SVG Images on iOS / OS X, using native rendering (CoreAnimation)

SVGKit SVGKit is a Cocoa framework for rendering SVG files natively: it's fast and powerful. Some additional info and links are on the wiki Versions:

null 4.3k Jan 3, 2023
Conical (angular) gradient for iOS written in Swift

AEConicalGradient Conical (angular) gradient in Swift I hope that somebody will find this useful. And nice. Usage AEConicalGradient is a minion which

Marko Tadić 82 Dec 27, 2022
🌈 Highly customizable Core Graphics based gradient view for iOS

MKGradientView Highly customizable Core Graphics based gradient view Features Available gradient types: Linear (Axial) Radial (Circular) Conical (Angu

Max Konovalov 167 Dec 27, 2022
GraphLayout - iOS UI controls to visualize graphs. Powered by Graphviz

GraphLayout GraphLayout - UI controls for graph visualization. It is powered by Graphviz. Graph visualization is a way of representing structural info

null 97 Sep 26, 2022
🎞 Powerful gradient animations made simple for iOS.

AnimatedGradientView is a UIView subclass which makes it simple to add animated gradients to your iOS app. It is written purely in Swift. Further docu

Ross Butler 431 Dec 12, 2022
The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo erase the drawing.

IOSObjC_KidsBoard The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo era

Haresh 0 Oct 28, 2021
Create Live Graphics in SwiftUI (iOS, tvOS & macOS)

PixelUI import SwiftUI import PixelUI struct ContentView: View { var body: some View { GeometryReader { geo in

Anton Heestand 21 Dec 17, 2022
A lightweight XMLParser for assembling and parsing XML values written for iOS 8+ in Swift 2.

Overview Description Requirements Installation Usage Author License Description XMLParser lets you convert a pure Swift dictionary into XML string and

Eugene Mozharovsky 75 Feb 2, 2022
πŸ”₯ πŸ”₯ πŸ”₯Support for ORM operation,Customize the PQL syntax for quick queries,Support dynamic query,Secure thread protection mechanism,Support native operation,Support for XML configuration operations,Support compression, backup, porting MySQL, SQL Server operation,Support transaction operations.

?? ?? ??Support for ORM operation,Customize the PQL syntax for quick queries,Support dynamic query,Secure thread protection mechanism,Support native operation,Support for XML configuration operations,Support compression, backup, porting MySQL, SQL Server operation,Support transaction operations.

null 60 Dec 12, 2022
Static Native Template and Dynamic Styling without any other app release

FileManager Project Students and Freshers, Good opportunity for you to learn and contribute in this project. Here you would learn how you can change t

Naveen Chauhan 3 Nov 30, 2021
Declarative text styles and streamlined Dynamic Type support for iOS

StyledText StyledText is a library that simplifies styling dynamic text in iOS applications. Instead of having to use attributed strings every time yo

Blue Apron 233 Oct 18, 2022
TRex πŸ¦– TRex makes OCR easy and accessible on a Mac

TRex ?? TRex makes OCR easy and accessible on a Mac. But what is OCR anyway? Imagine you have a PDF file or a Web page where you can't select the text

Ameba Labs 700 Dec 23, 2022
APDynamicGrid is a SwiftUI package that helps you create consistent and animatable grids.

APDynamicGrid Overview APDynamicGrid is a SwiftUI package that helps you create consistent and animatable grids. The DynamicGrid View preserves the sa

Antonio Pantaleo 29 Jul 4, 2022
Takes those cursed usernames you see on social networks and lets them be accessible to screen readers.

AccessibleAuthorLabel ?? Takes those cursed usernames you see on social networks and lets them be accessible to screen readers so everyone can partake

Christian Selig 40 Jan 25, 2022
PJFDataSource is a small library that provides a simple, clean architecture for your app to manage its data sources while providing a consistent user interface for common content states (i.e. loading, loaded, empty, and error).

PJFDataSource PJFDataSource is a small library that provides a simple, clean architecture for your app to manage its data sources while providing a co

Square 88 Jun 30, 2022