大佬教程收集整理的这篇文章主要介绍了如何在Xcode Story Board中添加有关多设备的动态字体大小,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
但由于字体大小固定,所有设备的字体大小都相同
(4,4.7,5.5英寸)
4英寸看起来不错.但在5.5英寸,这太小了
我想在任何设备中动态地发布和减少UIlabel字体大小.
有任何想法吗?
我做了一堂课
class UILabelDeviceClass : UILabel { @IBInspectable var iPhoneFontSize:CGFloat = 0 { didSet { overrideFontSize(iPhoneFontSizE) } } func overrideFontSize(fontSize:CGFloat){ let currentFontName = self.font.fontName var calculatedFont: UIFont? let bounds = UIScreen.mainScreen().bounds let height = bounds.size.height switch height { case 480.0: //Iphone 3,4,SE => 3.5 inch calculatedFont = UIFont(name: currentFontName,size: fontSize * 0.7) self.font = calculatedFont break case 568.0: //iphone 5,5s => 4 inch calculatedFont = UIFont(name: currentFontName,size: fontSize * 0.8) self.font = calculatedFont break case 667.0: //iphone 6,6s => 4.7 inch calculatedFont = UIFont(name: currentFontName,size: fontSize * 0.9) self.font = calculatedFont break case 736.0: //iphone 6s+ 6+ => 5.5 inch calculatedFont = UIFont(name: currentFontName,size: fontSizE) self.font = calculatedFont break default: print("not an iPhone") break } }
}
然后,设置类
然后,设定价值
快乐的编码!
以上是大佬教程为你收集整理的如何在Xcode Story Board中添加有关多设备的动态字体大小全部内容,希望文章能够帮你解决如何在Xcode Story Board中添加有关多设备的动态字体大小所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。