SwiftUI Quick Tip: Apply Text Transformations
Have you ever wondered how to apply text transformations in SwiftUI, such as small caps, lowercase small caps, or uppercase small caps? It’s actually pretty easy, as all available transformations are available and suggested by Xcode when specifying the font.
Consider the following example that applies the largeTitle font to text:
Text("Hello World!!!")
.font(.largeTitle)
Before applying any transformation, it’s necessary to explicitly set the class that the largeTitle
belongs to:
Text("Hello World!!!")
.font(Font.largeTitle)
Then, just press the dot key in your keyboard and Xcode will suggest all possible transformations that can be applied to the font:
For example, by applying the small caps effect on the text the result looks like this:
Text("Hello World!!!")
.font(Font.largeTitle.smallCaps())