Skip to content

Instantly share code, notes, and snippets.

@mazefest
Created June 17, 2025 15:35
Show Gist options
  • Select an option

  • Save mazefest/e71660cc663d7754ea223e93698757aa to your computer and use it in GitHub Desktop.

Select an option

Save mazefest/e71660cc663d7754ea223e93698757aa to your computer and use it in GitHub Desktop.
Expose font size in Xcode when selecting fonts.
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)
}
}
@mazefest
Copy link
Author

Screenshot 2025-06-17 at 10 31 11 AM

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