Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Load custom fonts within Swift playgrounds
//: Playground - noun: a place where people can play
import UIKit
let fontURL = NSBundle.mainBundle().URLForResource("PillGothic300mg-bold", withExtension: "ttf")
CTFontManagerRegisterFontsForURL(fontURL!, CTFontManagerScope.Process, nil)
var pillGothicFontBold = UIFont(name: "PillGothic300mg-bold", size: 30)
var attrs = [NSFontAttributeName : pillGothicFontBold!,
NSForegroundColorAttributeName : UIColor.whiteColor(),
NSBaselineOffsetAttributeName : 0.0]
let nameAttrSring = NSAttributedString(string: "Pill Gothic font 300mg Bold size 30", attributes: attrs)
@soffes

This comment has been minimized.

Copy link

commented Mar 28, 2018

In Swift 4.1:

let fontURL = Bundle.main.url(forResource: "PillGothic300mg-bold", withExtension: "ttf")
CTFontManagerRegisterFontsForURL(fontURL! as CFURL, CTFontManagerScope.process, nil)
let font = UIFont(name: "PillGothic300mg-bold", size: 30)!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.