Home > AI > IOS > SwiftUI >

Text with device compability

Use this font families.

import Foundation
import SwiftUI


class HomeGlobal: ObservableObject {
    // Device compability
    let screenSize: CGSize = UIScreen.main.bounds.size
    let screenWidth: CGFloat = UIScreen.main.bounds.width
    let screenHeight: CGFloat = UIScreen.main.bounds.height
    private let referenceWidth: CGFloat = 375    // IPhone 8
    private let referenceHeight: CGFloat = 667   // IPhone 8
    var scaleFactor: CGFloat  {
        screenWidth / referenceWidth
    }
    let defaultPadding: CGFloat = 16             // IPhone 8
    let defaultNavHeight: CGFloat = 44           // IPhone 8
    
    
    
    // Font device compability
    var fontLargeTitle: Font {
        Font.system(size: 35*scaleFactor)
    }
    var fontTitle: Font {
        Font.system(size: 30*scaleFactor)
    }
    var fontTitle2: Font {
        Font.system(size: 23*scaleFactor)
    }
    var fontTitle3: Font {
        Font.system(size: 20*scaleFactor)
    }
    var fontBody: Font {
        Font.system(size: 18*scaleFactor)
    }
    var fontHeadline: Font {
        Font.system(size: 17*scaleFactor)
    }
    var fontSubheadline: Font {
        Font.system(size: 15*scaleFactor)
    }
    var fontCallout: Font {
        Font.system(size: 15*scaleFactor)
    }
    var fontFootnote: Font {
        Font.system(size: 13*scaleFactor)
    }
    var fontCaption: Font {
        Font.system(size: 12*scaleFactor)
    }
    var fontCaption2 : Font {
        Font.system(size: 10*scaleFactor)
    }
}

https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/typography/

Relevant tags:

Leave a Reply