Created
October 4, 2016 04:01
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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