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)
// 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
//MARK: - Font Parts
public extension UIFont {
enum Family: String, CaseIterable {
case system = ".SFUIText" //".SFUI"
case inter = "Inter"
}
enum CustomWeight: String, CaseIterable {
@popcornomnom
popcornomnom / Localizable.swift
Last active September 18, 2019 14:23
iOS Localization Advices (Swift 5). Article link: http://www.popcornomnom.com/ios-localization-swift-5/
enum Localizable {
enum Global: String, LocalizableDelegate {
case cancel, close
}
enum WelcomePage: String, LocalizableDelegate {
case title = "welcomeTitle"
case ctaButtonTitle = "start"
case next
Text("my label")
.font(.init(.h3, .bold))
//Swift
let label = UILabel()
label.font = UIFont(.h3, .bold)
deinit {
stopwatch.stop()
}
func timeString(from timeInterval: TimeInterval) -> String {
let seconds = Int(timeInterval.truncatingRemainder(dividingBy: 60))
let minutes = Int(timeInterval.truncatingRemainder(dividingBy: 60 * 60) / 60)
let hours = Int(timeInterval / 3600)
return String(format: "%.2d:%.2d:%.2d", hours, minutes, seconds
}