Skip to content

Instantly share code, notes, and snippets.

@perpeer
Created September 26, 2020 13:09
Show Gist options
  • Select an option

  • Save perpeer/82b6873f400044d9622a29b6f7f7eff3 to your computer and use it in GitHub Desktop.

Select an option

Save perpeer/82b6873f400044d9622a29b6f7f7eff3 to your computer and use it in GitHub Desktop.
SwiftUI Font Extension
import SwiftUI
enum YanoneKaffeesatz: String {
case bold = "YanoneKaffeesatz-Bold"
case extraLight = "YanoneKaffeesatz-ExtraLight"
case light = "YanoneKaffeesatz-Light"
case medium = "YanoneKaffeesatz-Medium"
case regular = "YanoneKaffeesatz-Regular"
case semiBold = "YanoneKaffeesatz-SemiBold"
}
extension View {
func bold(size: CGFloat) -> some View {
self.font(.custom(YanoneKaffeesatz.bold.rawValue, size: size))
}
func extraLight(size: CGFloat) -> some View {
self.font(.custom(YanoneKaffeesatz.extraLight.rawValue, size: size))
}
func light(size: CGFloat) -> some View {
self.font(.custom(YanoneKaffeesatz.light.rawValue, size: size))
}
func medium(size: CGFloat) -> some View {
self.font(.custom(YanoneKaffeesatz.medium.rawValue, size: size))
}
func regular(size: CGFloat) -> some View {
self.font(.custom(YanoneKaffeesatz.regular.rawValue, size: size))
}
func semiBold(size: CGFloat) -> some View {
self.font(.custom(YanoneKaffeesatz.semiBold.rawValue, size: size))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment