Skip to content

Instantly share code, notes, and snippets.

@HarshilShah
Last active September 4, 2022 22:06
Show Gist options
  • Save HarshilShah/5df56b511acdfb895cfce001d1728620 to your computer and use it in GitHub Desktop.
Save HarshilShah/5df56b511acdfb895cfce001d1728620 to your computer and use it in GitHub Desktop.
A UIFont extension to use small caps San Francisco
//
// UIFont+SmallCaps.swift
//
// Created by Harshil Shah on 27/04/16.
// Copyright © 2016 Harshil Shah. All rights reserved.
//
import UIKit
extension UIFont {
class func smallCapsSystemFont(ofSize size: CGFloat, weight: UIFont.Weight = .regular) -> UIFont {
let descriptor = UIFont.systemFont(ofSize: size, weight: weight).fontDescriptor
let smallLettersToSmallCapsAttribute: [UIFontDescriptor.FeatureKey: Int] = [
.featureIdentifier: kLowerCaseType,
.typeIdentifier: kLowerCaseSmallCapsSelector ]
let capitalLettersToSmallCapsAttribute: [UIFontDescriptor.FeatureKey: Int] = [
.featureIdentifier: kUpperCaseType,
.typeIdentifier: kUpperCaseSmallCapsSelector ]
let newDescriptor = descriptor.addingAttributes([
.featureSettings: [
smallLettersToSmallCapsAttribute,
capitalLettersToSmallCapsAttribute
]
])
return UIFont(descriptor: newDescriptor, size: size)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment