Enter your custom font name in "Your Font Here"
.
/// A modifier to change `Font`
/// - Parameters:
/// - size: Size of `Font`
/// - fixedSize: If set to `true` then the font size will not change dynamically. Default is `false`
/// - Returns: A view of size and font
struct SiennaFont: ViewModifier {
let size: CGFloat
let fixedSize: Bool
let font = "Your Font Here"
func body(content: Content) -> some View {
content
.font(fixedSize ? .custom(font, fixedSize: size): .custom(font, size: size))
}
}
extension View {
/// A modifier to change `Font`
/// - Parameters:
/// - size: Size of `Font`
/// - fixedSize: If set to `true` then the font size will not change dynamically. Default is `false`
/// - Returns: A view of size and font
func myCustomFont(size: CGFloat, fixedSize: Bool = false) -> some View {
modifier(SiennaFont(size: size, fixedSize: fixedSize))
}
}
Then use it like if you want the text to change dynamically.
Text("Hello World!")
.myCustomFont(size: 40)
or if you want it fixed size then
Text("Hello World!")
.myCustomFont(size: 40, fixedSize: true)