I've read all the articles about supporting dynamic text size, but my problem is that I have a view consisting of shapes and some text. I needed to hard code the height of this view, so when a user uses a larger text size the text overlaps the shapes. What I would like to do is detect when a larger text size is used and increase the hard coded height of the view.
There is an environment value for that:
@Environment(\.sizeCategory) var sizeCategory
With that, you can do stuff like:
if sizeCategory > ContentSizeCategory.large {
// views for large text
} else {
// views for regular/small text
}
You should also check out the @ScaledMetric property wrapper, which will auto-scale your var based on the user’s text size:
@ScaledMetric var height: CGFloat = 100
Here's a nice summary of both: https://swiftwithmajid.com/2019/10/09/dynamic-type-in-swiftui/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With