resizableFont()

๐Ÿ“— ๅƒ่€ƒ๏ผšSwift Playgrounds for iPad (Keep Going with Apps)

import SwiftUI

// ๐ŸŒ€ view.resizableFont()
extension View {
    func resizableFont(
        maxSize : Double = 125, 
        minScale: Double = 0.01
    ) -> some View {
        self.modifier(FlexibleFontModifier(
            maxSize: maxSize, 
            minScale: minScale
        ))
    }
}

// ๐Ÿ‘” FlexibleFontModifier
private struct FlexibleFontModifier: ViewModifier {
    
    var maxSize : Double
    var minScale: Double
    
    func body(content: Content) -> some View {
        content
            .font(.system(size: maxSize))
            .minimumScaleFactor(minScale)
    }
}

Last updated