Correct Image and Font Scale on different Devices?

后端 未结 8 1976
日久生厌
日久生厌 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:54

    in programatically (X and Y) we pre define the values in constant :

    #define XScale [[UIScreen mainScreen] bounds].size.width / 320.0f
    #define YScale [[UIScreen mainScreen] bounds].size.height / 568.0f
    

    Then create UIImageView programatically

    var imageView : UIImageView
    imageView  = UIImageView(frame:CGRectMake(XScale *someValue, YScale * someValue, XScale *someValue, YScale *someValue));
    imageView.image = UIImage(named:"image.jpg")
    self.view.addSubview(imageView)
    

    based on your screen size we need to set Constant values. We use for iPhone5 and 4s screen.

提交回复
热议问题