1. 程式人生 > >swift 字體自適應,寬高自適應

swift 字體自適應,寬高自適應

true oat turn ont pre pin class lar ret

let kScreenWidth = UIScreen.main.bounds.width

let kScreenHeight = UIScreen.main.bounds.height



public func FitWidth(_ width: CGFloat) -> CGFloat {

    return width * kScreenWidth / 375.0

}

 

public func FitHeight(_ height: CGFloat) -> CGFloat {

    return height * kScreenHeight / 667.0

}

 

public func FitFont(_ font: CGFloat) -> UIFont {

    return UIFont(name: "PingFangSC-Regular", size: font * kScreenWidth / 375.0)!

}

swift 字體自適應,寬高自適應