Skip to content

Instantly share code, notes, and snippets.

@csfelipe
Last active November 26, 2015 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csfelipe/8bc959790065452a6fe4 to your computer and use it in GitHub Desktop.
Save csfelipe/8bc959790065452a6fe4 to your computer and use it in GitHub Desktop.
//
// UIFont+SFUIDisplay.swift
//
// Created by Felipe Gringo on 11/26/15.
// Copyright © 2015 Gringo, Inc. All rights reserved.
//
import Foundation
import UIKit
struct SFUIDisplayFontType : OptionSetType
{
let rawValue: Int
init(rawValue: Int) { self.rawValue = rawValue }
static internal let None = SFUIDisplayFontType(rawValue: 0)
static internal let Bold = SFUIDisplayFontType(rawValue: 1)
static internal let Semibold = SFUIDisplayFontType(rawValue: 2)
static internal let Heavy = SFUIDisplayFontType(rawValue: 3)
static internal let Black = SFUIDisplayFontType(rawValue: 4)
static internal let Medium = SFUIDisplayFontType(rawValue: 5)
static internal let Regular = SFUIDisplayFontType(rawValue: 6)
static internal let Thin = SFUIDisplayFontType(rawValue: 7)
static internal let Light = SFUIDisplayFontType(rawValue: 8)
static internal let Ultralight = SFUIDisplayFontType(rawValue: 9)
}
extension UIFont
{
class func SFUIDisplayFont(type: SFUIDisplayFontType, size: CGFloat)-> UIFont
{
var post:String
switch (type)
{
switch (type)
{
case SFUIDisplayFontType.Bold:
post = "Bold"
break
case SFUIDisplayFontType.Semibold:
post = "Semibold"
break
case SFUIDisplayFontType.Heavy:
post = "Heavy"
break
case SFUIDisplayFontType.Black:
post = "Black"
break
case SFUIDisplayFontType.Medium:
post = "Medium"
break
case SFUIDisplayFontType.Regular:
post = "Regular"
break
case SFUIDisplayFontType.Thin:
post = "Thin"
break
case SFUIDisplayFontType.Light:
post = "Light"
break
case SFUIDisplayFontType.Ultralight:
post = "Ultralight"
break
default:
post = "Regular"
break
}
}
let fontName:String = "SFUIDisplay-"+post
return UIFont(name: fontName, size: size)!
}
class func SFUIDisplayFontBoldWithSize(size: CGFloat) -> UIFont
{
return UIFont(name: "SFUIDisplay-Bold", size: size)!
}
class func SFUIDisplayFontSemiBoldWithSize(size: CGFloat) -> UIFont
{
return UIFont(name: "SFUIDisplay-Semibold", size: size)!
}
class func SFUIDisplayFontHeavyWithSize(size: CGFloat) -> UIFont
{
return UIFont(name: "SFUIDisplay-Heavy", size: size)!
}
class func SFUIDisplayFontBlackWithSize(size: CGFloat) -> UIFont
{
return UIFont(name: "SFUIDisplay-Black", size: size)!
}
class func SFUIDisplayFontMediumWithSize(size: CGFloat) -> UIFont
{
return UIFont(name: "SFUIDisplay-Medium", size: size)!
}
class func SFUIDisplayFontRegularWithSize(size: CGFloat) -> UIFont
{
return UIFont(name: "SFUIDisplay-Regular", size: size)!
}
class func SFUIDisplayFontThinWithSize(size: CGFloat) -> UIFont
{
return UIFont(name: "SFUIDisplay-Thin", size: size)!
}
class func SFUIDisplayFontLightWithSize(size: CGFloat) -> UIFont
{
return UIFont(name: "SFUIDisplay-Light", size: size)!
}
class func SFUIDisplayFontUltraLightWithSize(size: CGFloat) -> UIFont
{
return UIFont(name: "SFUIDisplay-Ultralight", size: size)!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment