'Globally Fix Font Size for System Fonts in iOS 14+
I want to use system fonts in my SwiftUI text, but these fonts automatically scale with the user's accessibility settings.
Text("abc").font(.system(size: 12))
Non-system fonts have this fixedSize initializer which allows it to not adjust to user settings, but there's no equivalent version for system fonts.
Text("abc").font(.custom("Arial", fixedSize: 12))
Another answer on here proposes using the environment to fix the font size, but unfortunately this doesn't apply to sheets. (This might be a bug similar to the one with environment objects not being passed into sheets). So I have to add this line for every view that is presented modally, plus the root view of my app.
var body: some View {
VStack {
...
}
.environment(\.sizeCategory, .large)
}
Is there a more elegant way to globally fix the font sizes for my app, rather than setting the environment key for every possible view that could be presented modally?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|