swiftโฉ custom โฉ extension โฉ Text+ โฉ .resizableFont()
.resizableFont()
This custom modifier allows your Text view's font size to fit the size of the view.
import SwiftUI // โญ๏ธ custom modifier struct FlexibleFontModifier: ViewModifier { var maxFontSize: Double var minScaleFactor : Double func body(content: Content) -> some View { content .font(.system(size: maxFontSize)) .minimumScaleFactor(minScaleFactor) } } // view extension extension View { // โญ๏ธ view.resizableFont() func resizableFont(maxFontSize: Double = 125, minScaleFactor: Double = 0.01) -> some View { self.modifier(FlexibleFontModifier(maxFontSize: maxFontSize, minScaleFactor: minScaleFactor)) } }
๐ ็ฏไพ
Text("Hello") .resizableFont() // โญ๏ธ custom modifier .frame(minWidth: 125)
.resizableFont() is a view modifier.
Text+๏ผ custom Text extensions.
Keep Going with Apps (Swift Playgrounds) โฉ Use model data in a view
Last updated 22 hours ago