Correct Image and Font Scale on different Devices?

后端 未结 8 1990
日久生厌
日久生厌 2021-02-01 05:28

I have a simple view with a text and an Image. I ran this app on iPhone6Plus and iPhone5. Then I made a screenshot of both and enlarged the iPhone5 screenshot such that it match

8条回答
  •  花落未央
    2021-02-01 05:56

    1. First turn off auto layout, auto resizing and size classes in storyboard.
    2. Click on Images.xcassets icon and select all your graphics. In attribute inspector set Devices property to "Device Specific" and set the checkbox checked against "iPhone" and "Retina 4-inch"
    3. Place all your graphics in 2x image set. You may place a higher resolution image set for better results with iPhone 6/6+.
    4. Design your view for a reference device say iPhone 5 (320x568 portrait).
    5. In your viewDidLoad method paste the following code

    self.view.transform=CGAffineTransformScale(CGAffineTransformIdentity,self.view.frame.size.width/320, self.view.frame.size.height/568);

    And you will have same result on iPhone 5/5s, iPhone 6/6+.

提交回复
热议问题