Skip to content

Instantly share code, notes, and snippets.

@rafaelcrz
Created July 5, 2023 23:19
Show Gist options
  • Save rafaelcrz/f280f2992c5de2e5438daca6b181902d to your computer and use it in GitHub Desktop.
Save rafaelcrz/f280f2992c5de2e5438daca6b181902d to your computer and use it in GitHub Desktop.
extension Font {
static func rounded(_ style: Font.TextStyle = .body, weight: Font.Weight = .semibold) -> Font {
return .system(size: style.size, weight: weight, design: .rounded)
}
}
extension Font.TextStyle {
var size: CGFloat {
switch self {
case .largeTitle: return 60
case .title: return 48
case .title2: return 34
case .title3: return 24
case .headline, .body: return 18
case .subheadline, .callout: return 16
case .footnote: return 14
case .caption, .caption2: return 12
@unknown default:
return 8
}
}
}
@rafaelcrz
Copy link
Author

            Text("Hello, world!")
                .font(.rounded())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment