有没有办法将 UILabel 字体设置为在大设备上更大而在小设备上更小?
我是否必须以编程方式执行此操作,每次都检查设备大小?
我现在的做法是:
class func hightlightPtSize(height: CGFloat) -> CGFloat {
return height / 25
}
class func notSoHighlightPtSize(height: CGFloat) -> CGFloat {
return height / 30
}
class func stdPtSize(height: CGFloat) -> CGFloat {
return height / 35
}
class func sizeForType(height: CGFloat, type: Int) -> CGFloat {
switch type {
case STD:
return stdPtSize(height: height)
case HIGHLIGHT:
return hightlightPtSize(height: height)
case NOT_SO_HIGH:
return notSoHighlightPtSize(height: height)
default:
return 0
}
}
最佳答案
我有解决你问题的办法。在我的 Objective C 代码下面。
float newFontSize = [UIScreen mainScreen].bounds.size.height * (fontSize / 568.0);
if ([UIScreen mainScreen].bounds.size.height < 500) {
newFontSize = [UIScreen mainScreen].bounds.size.height * (fontSize / 480.0);
}
self.label.font = [UIFont fontWithName:self.label.font.fontName size:newFontSize];
希望对你有帮助
关于ios - 调整设备尺寸的 UILabel 字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41438949/