1

How can I use small caps in Swift 5 (Storyboard) / Xcode 11?

Here's what I'm trying to accomplish.

I figured out how to do it in SwiftUI:

Text("Typography")
    .font(Font.system(.body).smallCaps())

But don’t now how to do it within a Storyboard-App.

This is my code so far:

labelBrand.font = UIFont.monospacedSystemFont(ofSize: 14, weight: UIFont.Weight.bold)
labelPorsche.font = UIFont.monospacedSystemFont(ofSize: 18, weight: UIFont.Weight.regular)

Thanks for your Help.

Daniel
  • 568
  • 3
  • 15

1 Answers1

0

The key is to get a font descriptor for the system font that you want (let’s call it desc), and apply the small caps as a feature:

let d = [
    UIFontDescriptor.FeatureKey.featureIdentifier: kLowerCaseType,
    UIFontDescriptor.FeatureKey.typeIdentifier: kLowerCaseSmallCapsSelector
]
let desc2 = desc.addingAttributes([.featureSettings:[d]])

Now translate the resulting font descriptor desc2 back to a UIFont.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thanks for your reply @matt. Unfortunately I don't understand how to implement your code. I got this two errors: https://i.stack.imgur.com/LqoOu.png – Daniel Apr 18 '20 at 22:29