Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Rita popcornomnom

:octocat:
View GitHub Profile
View AccessibillitySupport+Update.swift
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)
View FontManager+AccessibillitySupport.swift
///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
View FontManager.swift
//
// 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
View FontManager+AutoScaleSettings.swift
// 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
View FontManager+FontScaling.swift
//
// 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
View FontManager+Debug.swift
#if DEBUG
extension UIFont.Size {
var debugDescription: String { "\(self)" }
}
extension UIFont {
class func printAllFonts() {
let families = UIFont.Family.allCases
let sizes = UIFont.Size.allCases
View FontManagerBasic+SwiftUI.swift
//
// FontManager.swift
//
// Created by http://www.popcornomnom.com
// Copyright © 2019 Marharyta Lytvynenko. All rights reserved.
//
import UIKit
import SwiftUI
View FontManager4.swift
extension Font {
public static var title: Font { .init(.h3, .bold) }
}
View FontManager3.swift
extension UIFont {
public static var title: UIFont { .init(.h3, .bold) }
}
You can’t perform that action at this time.