Skip to content

Instantly share code, notes, and snippets.

@gaussbeam
Last active July 13, 2023 06:39
Show Gist options
  • Save gaussbeam/382117a9180df54ea78a09331a671035 to your computer and use it in GitHub Desktop.
Save gaussbeam/382117a9180df54ea78a09331a671035 to your computer and use it in GitHub Desktop.
import SwiftUI
struct FontStyleSampleView: View {
private var fontStyles = FontStyle.allCases
var body: some View {
List(fontStyles, id: \.self) { style in
Text(style.rawValue)
.fontStyle(style)
.foregroundColor(.black)
Text(displayString(from: style))
.font(.system(size: style.estimatedDefaultPointSize))
.fontWeight(style.weight)
.foregroundColor(.gray)
}
}
private func displayString(from style: FontStyle) -> String {
"\(style.rawValue), estimated: \(style.estimatedDefaultPointSize) pt"
}
}
struct FontStyleSampleView_Previews: PreviewProvider {
static var previews: some View {
FontStyleSampleView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment