fontsswiftuiuppercaseitalicsmallcaps

SwiftUI Font how to use uppercased() with LocalizedStringKey


I am trying to create a Font style that is both italic and uppercase. I am also using LocalizedStringKey to set my String. I tried using smallCaps() but this didn't work with italic() as answered HERE and if I try to use uppercased() on the LocalizedStringKey it just sets the key to uppercase rather than the String.

Anyone know a solution?

 extension Font {
    public static let Heading1: Font = system(size: 34, weight: .black, design: .default).italic()
}

Text("HELLO_WORLD").font(.Heading1)

Solution

  • Here is a solution. Tested with Xcode 11.4 / iOS 13.4

    demo

    Text(NSLocalizedString("HELLO_WORLD", comment: "").uppercased())
        .font(.Heading1)