iOS Different Font Sizes within Single Size Class for Different Devices

前端 未结 7 1541
死守一世寂寞
死守一世寂寞 2020-12-01 05:32

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

相关标签:
7条回答
  • 2020-12-01 06:29

    Edit: I don't recommend this anymore. This approach doesn't scale well when new devices come out. Use a combination of dynamic font sizes and size classes-specific fonts.


    Say a new iPhone model comes out, if you are 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)
    }
    
    0 讨论(0)
提交回复
热议问题