Skip to content

Instantly share code, notes, and snippets.

@theevo
Created March 11, 2023 07:14
Show Gist options
  • Save theevo/e1d7ef73a5fa48c4c66b5a0fc27bbc1a to your computer and use it in GitHub Desktop.
Save theevo/e1d7ef73a5fa48c4c66b5a0fc27bbc1a to your computer and use it in GitHub Desktop.
why does preferredFontDescriptor return an optional?
var countdownTimerLabel: UILabel = UILabel()
countdownTimerLabel.font = boldFont() ?? UIFont.systemFont(ofSize: 75, weight: .regular)
private func boldFont() -> UIFont? {
guard let descriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .largeTitle).withSymbolicTraits(.traitBold) else { return nil }
return UIFont(descriptor: descriptor, size: 75)
}
print("What font? \(countdownTimerLabel.font.fontName)") // .SFUI-Bold
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment