Skip to content

Instantly share code, notes, and snippets.

View popcornomnom's full-sized avatar
:octocat:

Rita Lytvynenko popcornomnom

:octocat:
View GitHub Profile
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
///Update fonts after dynamic fonts settings was changed
if traitCollection.preferredContentSizeCategory != previousTraitCollection?.preferredContentSizeCategory {
setFonts()
}
}
private func setFonts() {
title.font = UIFont(.h3, .black)
subtitle.font = UIFont(.bodyM, .medium)
///optional type in case if you want turn off acessability support
private let acessabilitySettings: DynamicTypeSettings? = DynamicTypeSettings()
private class DynamicTypeSettings {
let maxPointSizeScaleFactor: CGFloat
init(maxPointSizeScaleFactor: CGFloat = 1.25) {
self.maxPointSizeScaleFactor = maxPointSizeScaleFactor
//
// FontManager.swift
//
// Created by http://www.popcornomnom.com
// Copyright © 2020 Marharyta Lytvynenko. All rights reserved.
//
import UIKit
///optional type in case if you don't want to support scaled font yet
// somewhere here is a declaration of the Font Style parts
// https://gist.github.com/popcornomnom/5288be0c003fedff3e9d43c332837dca
// and func stringName(_, _) -> String
// https://gist.github.com/popcornomnom/1238714fea8d9a8efa109782958a5b99
///optional type in case if you don't want to support scaled font yet
private let autoScaleSettings: AutoScaleSettings? = AutoScaleSettings()
private class AutoScaleSettings {
let mostPopularScreenWidth: CGFloat = 375
//
// FontManager.swift
//
// Created by http://www.popcornomnom.com
// Copyright © 2020 Marharyta Lytvynenko. All rights reserved.
//
import UIKit
///optional type in case if you don't want to support scaled font yet
#if DEBUG
extension UIFont.Size {
var debugDescription: String { "\(self)" }
}
extension UIFont {
class func printAllFonts() {
let families = UIFont.Family.allCases
let sizes = UIFont.Size.allCases
//
// FontManager.swift
//
// Created by http://www.popcornomnom.com
// Copyright © 2019 Marharyta Lytvynenko. All rights reserved.
//
import UIKit
import SwiftUI
extension Font {
public static var title: Font { .init(.h3, .bold) }
}
extension UIFont {
public static var title: UIFont { .init(.h3, .bold) }
}
Text("my label")
.font(.init(.h3, .bold))