Created
December 23, 2021 12:02
-
-
Save ferologics/94f6575b02faa39dcab9f4a028782751 to your computer and use it in GitHub Desktop.
this example uses Dynamic Font with respect to line height line height
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Helper | |
struct Layout { // this uses Dynamic Font and calculates spacing for correct line height | |
static let weight = SwiftUI.Font.Weight.semibold | |
static let size = UIFontMetrics.default.scaledValue(for: 17) | |
static let lineHeight = UIFontMetrics.default.scaledValue(for: 22) | |
static let uiFont = UIFont.systemFont(ofSize: size, weight: weight.toUIKit()) | |
static let spacing = max(0, lineHeight - uiFont.lineHeight) | |
} | |
// MARK: - Usage | |
struct ContentView: View { | |
var body: some View { | |
Text("Hello nerd") | |
.font(.system(size: Layout.size, weight: Layout.weight)) | |
.lineSpacing(Layout.lineHeight) | |
.padding(.vertical, Layout.spacing/2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment