Vincentin
Vincentin

Reputation: 57

Fixed font size in iOS 14 widget with SwiftUI

For an iOS 14 widget I want to fix the font size in the widget, even when a user has its settings to bigger type in accessibility settings (larger type). I want this because the text is already very big (big digital clock widget), and if it is even bigger the text falls of the widget and therefore is not legible. I am using a custom font.

I tried to fix the font size with .font(.custom("MyCustomFont", size: 17)). But even then the type is rendered bigger depending on user settings. How can I permanently fix font size in a iOS 14 widget? Is there a workaround or another method to fix font size for the widget?

Upvotes: 1

Views: 1390

Answers (1)

pawello2222
pawello2222

Reputation: 54466

You can use .environment(\.sizeCategory, .large) to enforce the size category. Here is an example:

var body: some View {
    VStack {
        Text("text1")
        Text("text2")
    }
    .environment(\.sizeCategory, .large)
}

The default category is large but here you can find more categories.

Upvotes: 1

Related Questions