Coming soon - Get a detailed view of why an account is flagged as spam!
view details
19
How do I create a CTFont object for the San Francisco font on iOS 13?
Author Summary
iamthatis is in San Francisco, CA
Post Body

Up until iOS 13 I was able to create a CTFont object (it's a weird low level use case that doesn't permit UIFont) with:

CTFontCreateWithName((UIFont.systemFont(ofSize: 17.0).fontName as CFString), 16, nil)

The fontName in there is just .SFUI-Regular. Starting on iOS 13 it got angry:

CoreText performance note: Client called CTFontCreateWithName() using name ".SFUI-Regular" and got font with PostScript name "TimesNewRomanPSMT". For best performance, only use PostScript names when calling this API.

Okay, PostScript name. Not 100% sure what that is, but okay. I tried looking it up in the macOS Font Book. For San Francisco it says PostScript name: "SFProText-Regular". I plug that in:

CTFontCreateWithName(("SFProText-Regular" as CFString), 16, nil)

It returns… Helvetica:

<UICTFont: 0x108f220a0> font-family: "Helvetica"; font-weight: normal; font-style: normal; font-size: 16.00pt

Okay, maybe the macOS Font Book is wrong. Let's get it manually:

CGFont((UIFont.systemFont(ofSize: 16.0).fontName as NSString))!.postScriptName

Which outputs ".SFUI-Regular". Yeah the one from the beginning that makes it angry and turns into Times New Roman. We've came full circle.

What am I doing wrong?

Swift or Objective-C, doesn't matter.

EDIT: Heck how do you even create a UIFont from a string in iOS 13? I can't even get that working. https://i.imgur.com/zqW1stf.png

Author
Account Strength
100%
Account Age
13 years
Verified Email
Yes
Verified Flair
No
Total Karma
1,715,057
Link Karma
529,042
Comment Karma
607,499
Profile updated: 5 days ago
Posts updated: 3 months ago
Objective-C / Swift

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 years ago