Skip to content

Instantly share code, notes, and snippets.

View popcornomnom's full-sized avatar
:octocat:

Rita Lytvynenko popcornomnom

:octocat:
View GitHub Profile
//Swift
let label = UILabel()
label.font = UIFont(.h3, .bold)
@available(iOS 13.0, *)
extension Font {
init(_ size: UIFont.Size, _ weight: UIFont.CustomWeight) {
self.init(.defaultFamily, size, weight)
}
init(_ family: UIFont.Family = .defaultFamily,
_ size: UIFont.Size, _ weight: UIFont.CustomWeight) {
self.init(UIFont(family, size, weight))
//
// FontManager.swift
//
// Created by http://www.popcornomnom.com
// Copyright © 2019 Marharyta Lytvynenko. All rights reserved.
//
import UIKit
//MARK: - Font Parts
//put Family and Weight together
private class func stringName(_ family: Family, _ weight: CustomWeight) -> String {
let fontWeight: String
switch (family, weight) {
case (.inter, .heavy):
fontWeight = CustomWeight.semibold.rawValue
case (.inter, .light):
fontWeight = "\(weight.rawValue)BETA"
default:
fontWeight = weight.rawValue
//MARK: - Font Parts
public extension UIFont {
enum Family: String, CaseIterable {
case system = ".SFUIText" //".SFUI"
case inter = "Inter"
}
enum CustomWeight: String, CaseIterable {
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
}
import Foundation
class Stopwatch {
// MARK: Private Properties
private let step: Double
private var timer: Timer?
//The time when counting was started
private let step: Double = 1.0 //1 second
private var timer: Timer?
//MARK: Timer lifecycle
private func initTimer() {
let action: (Timer)->Void = { [weak self] timer in
guard let strongSelf = self else {
return
@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