传入一个label或者button,传入5s,6和6+的文字尺寸 快速定义文字大小

时间:2023-03-10 08:43:43
传入一个label或者button,传入5s,6和6+的文字尺寸 快速定义文字大小
func isIphone6() -> Bool {

    if screenWidth() >  {

        return true
}
else {
return false
}
} func isIphone6Plus() -> Bool { if screenWidth() > { return true
}
return false
} func fontSize(aView: UIView, fivs: CGFloat, six: CGFloat, sixPlus: CGFloat) { if (aView as? UILabel) != nil { if isIphone6Plus() {
(aView as UILabel).font = UIFont.systemFontOfSize(sixPlus)
}
else if isIphone6() {
(aView as UILabel).font = UIFont.systemFontOfSize(six)
}
else {
(aView as UILabel).font = UIFont.systemFontOfSize(fivs)
}
}
else if (aView as? UIButton) != nil {
if isIphone6Plus() {
(aView as UIButton).titleLabel!.font = UIFont.systemFontOfSize(sixPlus)
}
else if isIphone6() {
(aView as UIButton).titleLabel!.font = UIFont.systemFontOfSize(six)
}
else {
(aView as UIButton).titleLabel!.font = UIFont.systemFontOfSize(fivs)
}
}
}