All Projects β†’ Mindgrub β†’ Swash

Mindgrub / Swash

Licence: MIT License
Fonts in iOS made safe, expressive, and dynamic.

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to Swash

MultiFontViewKotlin-Android
MultiFontViewKotlin library can be used to select custom fonts for the view dynamically in your XML
Stars: ✭ 13 (-82.19%)
Mutual labels:  font, fonts, custom-fonts
react-native-custom-fonts
React Native Custom Fonts πŸ“š
Stars: ✭ 19 (-73.97%)
Mutual labels:  font, fonts, custom-fonts
eczar
Eczar: fonts for Devanagari and Latin
Stars: ✭ 52 (-28.77%)
Mutual labels:  font, fonts
rofi-fontawesome
fontawesome icon list for rofi dmenu
Stars: ✭ 58 (-20.55%)
Mutual labels:  font, fonts
fonts
Web fonts that you probably won't find in a CDN
Stars: ✭ 26 (-64.38%)
Mutual labels:  font, fonts
Acy-Font
θ‡ͺεˆΆζ‰‹ε†™ε­—δ½“γ€‚A hand-writing font set.
Stars: ✭ 20 (-72.6%)
Mutual labels:  font, fonts
Fonts
A curation of fonts from all over the world.
Stars: ✭ 144 (+97.26%)
Mutual labels:  font, fonts
baseline
New method for creating leading on the web
Stars: ✭ 31 (-57.53%)
Mutual labels:  font, fonts
Iosevka-Mayukai
Font based on Iosevka Custom Build, with combination from Iosevka SS04 Menlo, SS07 Monaco, SS09 Source Code Pro, SS12 Ubuntu Mono, SS14 Jetbrains Mono, Hack Style, and some Nerd Font Patching.
Stars: ✭ 149 (+104.11%)
Mutual labels:  font, fonts
bitsnpicas
Bits'N'Picas - Bitmap & Emoji Font Creation & Conversion Tools
Stars: ✭ 171 (+134.25%)
Mutual labels:  font, fonts
hzk-pixel-font
δΈ­ζ–‡εƒη΄ ε­—δ½“οΌŒ12 ε’Œ 16 像素。
Stars: ✭ 14 (-80.82%)
Mutual labels:  font, fonts
homecomputer-fonts
Variable fonts based on the Commodore 64 and Amiga fonts.
Stars: ✭ 58 (-20.55%)
Mutual labels:  font, fonts
sysfont
Golang identification and matching of system fonts
Stars: ✭ 29 (-60.27%)
Mutual labels:  font, fonts
FontRegister
FontRegister is a small Windows utility to install fonts and/or repair the font registry via commandline.
Stars: ✭ 17 (-76.71%)
Mutual labels:  font, fonts
hoard-of-bitfonts
turns out I like bitmap fonts
Stars: ✭ 811 (+1010.96%)
Mutual labels:  font, fonts
fontman
Manage and update your installed fonts.
Stars: ✭ 20 (-72.6%)
Mutual labels:  font, fonts
fdiff
An OpenType table diff tool for fonts. Based on the fontTools TTX format.
Stars: ✭ 33 (-54.79%)
Mutual labels:  font, fonts
apple-emoji-linux
Apple Color Emoji for Linux
Stars: ✭ 392 (+436.99%)
Mutual labels:  font, fonts
DBSScouterFont
Scouter Language Font as seen in Dragon Ball Super: Broly
Stars: ✭ 21 (-71.23%)
Mutual labels:  font, fonts
font-wonder-unit
Free and open source sans-serif font, brought to you by Wonder Unit.
Stars: ✭ 57 (-21.92%)
Mutual labels:  font, fonts

Swash

Version Swift 5.1 Platforms Carthage compatible License

Swash is a simple, safe, and expressive abstraction of UIFont with baked-in support for dynamic type.

Usage

To define a custom font, just create a String enum that conforms to the Font protocol.

enum Papyrus: String, Font {
    case regular = "Papyrus"
    case condensed = "Papyrus-Condensed"
}

That's all you need to start using your font in your project!

Static Sizes

label.font = Papyrus.regular.of(size: 17)

Dynamic Type (iOS 11+)

Uses UIFontMetrics for scaling. Setting adjustsFontForContentSizeCategory to true tells the label to automatically update the font when the user changes their content size preference. See our blog post for guidance on choosing default sizes for text styles, or just use Swash's provided defaults pulled from Apple's Human Interface Guidelines for iOS, watchOS, and tvOS.

label1.adjustsFontForContentSizeCategory = true
label2.adjustsFontForContentSizeCategory = true

label1.font = Papyrus.condensed.of(textStyle: .headline)
// Optional size cutoff and default size.
label2.font = GillSans.bold.of(textStyle: .title1, defaultSize: 28, maxSize: 38)

Dynamic Type Demo

Dynamic Type (Before iOS 11)

Uses system font scaling, no default size value. adjustsFontForContentSizeCategory requires the use of UIFontMetrics, so it is of no use for custom fonts before iOS 11. You'll have to update the fonts manually, either in traitCollectionDidChange(_:) or by observing the UIContentSizeCategoryDidChange notification.

label.font = Papyrus.condensed.of(style: .headline)
// Optional size cutoff
label.font = GillSans.bold.of(style: .title1, maxSize: 30)

System Font

You can use SystemFont to support dynamic type for different weights and further unify the font syntax in your project.

label1.font = SystemFont.light.of(size: 17)
label2.adjustsFontForContentSizeCategory = true
label2.font = SystemFont.preferred.of(textStyle: .body)
label3.font = SystemFont.semiboldItalic.of(textStyle: .body, maxSize: 30)

Important note: adjustsFontForContentSizeCategory only works with SystemFont for the preferred weight with a nil maxSize value. In any other case, you will need to update the font either in traitCollectionDidChange(_:) or by observing the UIContentSizeCategoryDidChange notification. This is because the preferred weight directly returns the result of UIFont.preferredFont(forTextStyle:).

Bold Text Device Setting

You can implement the boldTextMapping property on any Font in order to support the "Bold Text" device setting on iOS and tvOS.

var boldTextMapping: MyFont {
    switch self {
    case .regular: return .bold
    case .bold: return .black
    case .black: return self
    }
}

Now every regular MyFont instance will become bold if the user has "Bold Text" turned on in their device settings.

If you'd like, you can observe UIAccessibility.boldTextStatusDidChangeNotification via NotificationCenter and set your fonts when that updates.

Font Cascading

You can implement the static cascadeList property on any Font in order to support font cascading. In the event that your font does not support a character that is used in a label, this list will provide fallback fonts to use.

enum Papyrus: String, Font {
    case condensed = "Papyrus-Condensed"
    case regular = "Papyrus"
    
    var cascadeList: [CascadingFontProperties] {
        [.init(Damascus.regular)]
    }
}

Papyrus does not support Arabic characters. So, here we've provided Damascus as a fallback. If no fallback is provided, the system font will be used for unsupported characters.

Generate Boilerplate

Swash can attempt to log your font boilerplate for you!

Swash.logBoilerplate(forFontsWithFamilyNamesContaining: "gill")

Output:

enum GillSans: String, Font {
    case GillSans-Italic = "GillSans-Italic"
    case GillSans-SemiBold = "GillSans-SemiBold"
    case GillSans-UltraBold = "GillSans-UltraBold"
    case GillSans-Light = "GillSans-Light"
    case GillSans-Bold = "GillSans-Bold"
    case GillSans = "GillSans"
    case GillSans-SemiBoldItalic = "GillSans-SemiBoldItalic"
    case GillSans-BoldItalic = "GillSans-BoldItalic"
    case GillSans-LightItalic = "GillSans-LightItalic"
}

Just copy-paste the output into your project. You'll probably still need to doctor the case names a bit.

Debug Crashing

If your custom font fails to initialize, assertionFailure(_:file:line:) is called. This will crash debug builds with the default -Onone compiler optimization set. This is to help identify failed font initializations which can otherwise be hard to catch. Release builds with higher optimization levels will NOT crash, so you don't have to worry about your app crashing in production over a silly font.

Installation

CocoaPods

pod 'Swash'

Carthage

github "Mindgrub/Swash"

Make sure to specify your platform when you update (e.g. carthage update --platform iOS). Otherwise all 3 frameworks (iOS, tvOS, and watchOS) will be added.

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].