Created
June 17, 2025 15:35
-
-
Save mazefest/e71660cc663d7754ea223e93698757aa to your computer and use it in GitHub Desktop.
Expose font size in Xcode when selecting fonts.
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
| import Foundation | |
| import SwiftUI | |
| enum FontSize { | |
| /**Size 28.0 */ | |
| case title | |
| /**Size 22.0 */ | |
| case title2 | |
| /**Size 20.0 */ | |
| case title3 | |
| /**Size 15.0 */ | |
| case subHeadine | |
| /**Size 17.0 */ | |
| case body | |
| /**Size 16.0 */ | |
| case callout | |
| /**Size 11.0 */ | |
| case caption | |
| /**Size 10.0 */ | |
| case caption2 | |
| /** | |
| Custom font size | |
| */ | |
| case size(Double) | |
| // Hard coded font sizes | |
| var value: Double { | |
| return switch self { | |
| case .title: 28.0 | |
| case .title2: 22.0 | |
| case .title3: 20.0 | |
| case .subHeadine: 15.0 | |
| case .body: 17.0 | |
| case .callout: 16.0 | |
| case .caption: 11.0 | |
| case .caption2: 10.0 | |
| case .size(let value): value | |
| } | |
| } | |
| } | |
| // View Modifier | |
| extension View { | |
| func font(font: FontSize) -> some View { | |
| self.modifier(FontSizeViewModifier(font: font)) | |
| } | |
| } | |
| struct FontSizeViewModifier: ViewModifier { | |
| var font: FontSize | |
| func body(content: Content) -> some View { | |
| content.font(.system(size: FontSize.body.value)) | |
| } | |
| } | |
| // Example Use | |
| struct Test: View { | |
| var body: some View { | |
| Text("WeeWoo").font(font: .body) | |
| } | |
| } |
Author
mazefest
commented
Jun 17, 2025

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