需要通過CGFont
爲以下功能快速轉換UIFont到CGFont?
CGFontCreateCopyWithVariations(<#font: CGFont!#>, <#variations: CFDictionary!#>))
需要通過CGFont
爲以下功能快速轉換UIFont到CGFont?
CGFontCreateCopyWithVariations(<#font: CGFont!#>, <#variations: CFDictionary!#>))
這裏是一個小例子:
var font = UIFont.systemFontOfSize(15.0)
var fontName = font.fontName as NSString
var cgFont = CGFontCreateWithFontName(fontName);
var copiedFont = CGFontCreateCopyWithVariations(cgFont, nil)
明白了。非常感謝 :) – 2014-09-25 11:21:25
就遇上了這樣斯威夫特4和接受的答案不再是相當有效的。下面拿了UIFont
,給了我一個可用的CGFont
:
if let uiFont = UIFont(name: "Helvetica-Bold", size: 36.0),
let cgFont = CGFont(uiFont.fontName as CFString) {
// Do stuff
}
這個怎麼樣 - http://stackoverflow.com/questions/9205709/how-to-convert-cgfontref-to-uifont – Grimxn 2014-09-25 09:33:39
嗯,他是問對於Swift,但我想這也回答了這個問題:你需要在這裏應用Objective-C。 – 2014-09-25 09:43:13
感謝一噸Grimxn和Peter Branforn – 2014-09-25 11:20:31