单粒级为不同的设备内的iOS不同的字体大小 [英] iOS Different Font Sizes within Single Size Class for Different Devices
问题描述
在iOS 8的,我们可以设计为每个尺寸类不同的UI布局。我面临的问题是,我设计了紧凑的宽度和高度定期(大小类为人像所有iPhone)的布局,但我想保持标签3.5和4英寸设备(iPhone 4和5个较小的字体大小),则相对较大的4.7英寸(iPhone 6)和更多更大的5.5英寸(iPhone 6加)设备。我已经搜查,但未能找到一个解决方案,为同样大小的类中不同的设备设置不同的字体大小。
In iOS 8, we can design a different UI layout for each size class. The issue I'm facing is, I've designed a layout for Compact Width and Regular Height (size class for all iPhones in portrait) but i want to keep font size of labels smaller for 3.5 and 4 inch devices (iPhone 4 and 5), then relatively bigger for 4.7 inch (iPhone 6) and more bigger for 5.5 inch (iPhone 6 Plus) devices. I've searched but unable to find a solution to set different font size for different devices within same size class.
推荐答案
自动布局和大小的类不能针对具体的屏幕尺寸,因为他们的目的不是为。苹果不希望你对目标设备,以帮助您更好的维护您的code。
Auto Layout and Size Classes can't target specific screen sizes because they aren't meant for that. Apple doesn't want you to target devices to help you better maintain your code.
说新的iPhone机型出来,使用自动布局和大小类不必手动修复所有的约束,使您的应用这个新设备兼容。但是,您仍然可以设置字体大小的UILabel
使用以下code:
Say a new iPhone model comes out, using Auto Layout and Size Classes you don't have to fix all the constraints manually to make your app compatible with this newer device. However, you can still set the font size of the UILabel
using the following code:
if UIScreen.mainScreen().bounds.size.height == 480 {
// iPhone 4
label.font = label.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.height == 568 {
// IPhone 5
label.font = label.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.width == 375 {
// iPhone 6
label.font = label.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.width == 414 {
// iPhone 6+
label.font = label.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.width == 768 {
// iPad
label.font = label.font.fontWithSize(20)
}
这篇关于单粒级为不同的设备内的iOS不同的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!