Created
January 27, 2023 10:45
-
-
Save hacknicity/7195e1c65c9c5db53419edf6b2f19dc6 to your computer and use it in GitHub Desktop.
SwiftUI sample showing different system font widths, including an undocumented extra expanded width
This file contains 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
// | |
// ContentView.swift | |
// SystemFontWidths | |
// | |
// Created by Geoff Hackworth on 27/01/2023. | |
// | |
import SwiftUI | |
struct ContentView: View { | |
private let fontWidths: [Font.Width] = [.compressed, .condensed, .standard, .expanded, .extraExpanded] | |
var body: some View { | |
VStack(spacing: 8) { | |
ForEach(fontWidths, id: \.self) { width in | |
HStack(spacing: 8) { | |
Text("Hello, world!") | |
.frame(maxWidth: .infinity, alignment: .trailing) | |
Text("\(width.name)") | |
.frame(maxWidth: .infinity, alignment: .leading) | |
} | |
.fontWidth(width) | |
} | |
} | |
.padding() | |
} | |
} | |
extension Font.Width { | |
/// Undocumented Font.Width | |
static let extraExpanded = Font.Width(0.3) | |
} | |
private extension Font.Width { | |
var name: String { | |
let names: [Font.Width: String] = [ | |
.compressed: "compressed", | |
.condensed: "condensed", | |
.standard: "standard", | |
.expanded: "expanded", | |
.extraExpanded: "extraExpanded" | |
] | |
return names[self] ?? "unknown" | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Author
hacknicity
commented
Jan 27, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment