Reputation: 161
Need to pass CGFont
for the below function
CGFontCreateCopyWithVariations(<#font: CGFont!#>, <#variations: CFDictionary!#>))
Upvotes: 4
Views: 6256
Reputation: 36670
Ran into this with Swift 4 and the accepted answer is no longer quite valid. The following took a UIFont
and gave me a usable CGFont
:
if let uiFont = UIFont(name: "Helvetica-Bold", size: 36.0),
let cgFont = CGFont(uiFont.fontName as CFString) {
// Do stuff
}
Upvotes: 5
Reputation: 27345
Here is a small example:
var font = UIFont.systemFontOfSize(15.0)
var fontName = font.fontName as NSString
var cgFont = CGFontCreateWithFontName(fontName);
var copiedFont = CGFontCreateCopyWithVariations(cgFont, nil)
Upvotes: 10