Skip to content

Instantly share code, notes, and snippets.

@fmo91
Created October 4, 2016 04:01
Show Gist options
  • Save fmo91/70103edced279a8bb2fc3d6498e2c0b3 to your computer and use it in GitHub Desktop.
Save fmo91/70103edced279a8bb2fc3d6498e2c0b3 to your computer and use it in GitHub Desktop.
Handy extension to use custom fonts in your iOS Swift application without hardcoding strings.
//
// UIFont+Custom.swift
//
// Created by Fernando Ortiz on 10/1/16.
// Copyright © 2016 Fernando Martín Ortiz. All rights reserved.
//
import UIKit
enum CustomFont: String {
case firaSansMedium = "FiraSans-Medium"
case firaSansRegular = "FiraSans-Regular"
case firaSansBold = "FiraSans-Bold"
}
extension UIFont {
/**
Initializes an UIFont using a predefined enumeration and a given size.
*/
convenience init?(customFont: CustomFont, withSize size: CGFloat) {
self.init(name: customFont.rawValue, size: size)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment