当我使用UILabel
时,我将系统字体设置为:
label.font = UIFont.systemFontOfSize(18, weight: UIFontWeightMedium)
现在我尝试使用CATextLayer
并在线搜索,发现iOS 9的系统字体为San Francisco
,字体名称为.SFUIText-Medium
,因此我尝试设置字体名称为:
textLayer = CATextLayer()
textLayer.font = CTFontCreateWithName(".SFUIText-Medium", 18, nil)
但是,设备屏幕上显示的字体与UILabel
& CATextLayer
,如上所述。这里CATextLayer
使用的字体名称是什么,这样我可以使用与UILabel
完全相同的字体?
答案 0 :(得分:6)
自iOS 7.0起,CTFont
和UIFont
已被“免费桥接”。这意味着您可以将CTFont
视为let view = UIView(frame: CGRectMake(0, 0, 200, 100))
view.backgroundColor = UIColor.whiteColor()
let layer = CATextLayer()
layer.font = UIFont.systemFontOfSize(18, weight: UIFontWeightMedium)
layer.string = "Hello"
layer.frame = view.bounds
layer.foregroundColor = UIColor.blackColor().CGColor
view.layer.addSublayer(layer)
XCPlaygroundPage.currentPage.liveView = view
print(layer.font)
,反之亦然。因此:
Optional(<UICTFont: 0x7f904bf38960> font-family: ".SFUIText-Medium"; font-weight: normal; font-style: normal; font-size: 18.00pt)
结果:
def exec(f: (a:Int, b:Int) => Boolean): Boolean = f(a,b)
^ ^
| |
// These are supposed to be types, but a: Int and b: Int aren't types,
// they are identifiers with type ascriptions.