Scale background image to iPhone 10

半腔热情 提交于 2020-01-06 03:58:12

问题


I'm using Swift 4, XCode 9. I have an iOS application which has a background image which was set using storyboard. The actual storyboard file is viewed from the frame of reference of an iPhone SE. However, I've never had a problem with the image scaling to bigger phone sizes, except now for iPhone 10. It won't fill the whole screen. How can I fix this? The background is displayed through an image view. I've tried changing the height of the image view both via story board and programmatically with no luck. Again, this only is a problem on iPhone 10.

EDIT: I've somewhat fixed this problem by adding a specific iPhone X Launch Image, but now my components are all shifted to the left


回答1:


iPhone X has a different screen size of 375 × 812 points (1125×2436 pixels). The iPhone X's aspect ratio is approximately 9:19.5 So it is different. Here is Apple's official guide which tells you how to handle images. https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x/

Please show us some code or image so that we can solve your problem.




回答2:


There are few steps you should be careful.

Step 1: Choose the device iPhone X in Interface builder.

Step 2: Add a full image to the ViewController.

Step 3: Add constraints (Should be all Zero) by selecting the bottom menu.

We all set. If you start adding from iPhone X or later devices, it will automatically adjust the bottom, top, left and right constraints accordingly all the previous devices.

NB: While we adding manual constraints, be aware that the SafeAreaLayout has the first priority than the manual constraints.

I believe this will help somebody. Cheers.



来源:https://stackoverflow.com/questions/48604425/scale-background-image-to-iphone-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!