'Use dynamic text size .largeTitle but always 18% larger than normal in SwiftUI
I want to use dynamic text sizes in the system font. But our design wants the default large title to be a bit bigger than the 34pt Apple default.
How do I make my SwiftUI style
.font(.largeTitle)
relatively larger, i.e. 40pt at system default text size, but still scale proportionately when the user changes the system text size? Always 18% bigger than a normal .largeTitle.
I don't want to specify the San Francisco font name using
.custom(<name>, size: <Float>, relativeTo: <Font.TextStyle>)
as this generates a warning and misses out on getting the best optical variant.
I can use UIFont functions to adjust font metrics but I cannot convert the too-small SwiftUI Font to UIFont.
Solution 1:[1]
You just need to add a .scaleEffect() modifier, like this:
Text("Hello, world!")
.font(.largeTitle)
.scaleEffect(1.18)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HunterLion |
