Truly universal iOS launch screen using Launch Screen.xib template?

非 Y 不嫁゛ 提交于 2019-12-12 07:36:10

问题


So, starting with Xcode 6 we have got a new super-useful feature of Launch Screen template

According to it's description it can help create a launch screen that will work correctly on every device/resolution/orientation and we don't have to make a bunch of different screens for different resolutions with Assets Catalog anymore.

but... I have failed to find any useful tutorial on how to actually use this to make a single launch screen using a single image for all resolutions (only for landscape).

I know how to make a UI element centered on all resolutions using constraints, but i can't figure out how to make my UIImage scale to fill screen height on all resolutions. If i just resize my UIImage to fill current screen size selected in Simulated Metrics - it will fill only that one, but will not work with other screen sizes..

Can somebody give me a clue? how to make UIImage fill entire screen for all resolutions using this Launch Screen template?


回答1:


If you simply just want to fill your launch screen with an image in every screen size, you can use leading, trailing, top and bottom constraints between your UIImageView and the superview. So:

Step 1 Add your UIImageView to your LaunchScreen.xib and set whatever image it should display.

Step 2 Select your newly added UIImageView and click the "Pin" icon at the bottom right of Interface Builder.

Step 3 Select all 4 edges og set the constants to 0. This makes sure that your UIImageView has 0 points of space to the superview on every edge.

It looks like this:

That said, you should consider if this is the way to go. The idea of having a .xib file as a launch screen is really intended to replace the need of having to show full screen launch images. Instead, consider placing whatever elements your launch image contains in the interface builder instead. Also remember that you're (unfortunately) not able to tie any code together with your launch screen .xib file.




回答2:


You need to add an UIImageView to view to your xib file and set the constraints to fill the entire screen, e.g. spacing left, right, top and bottom equal to 0. (You already mentioned you can do this, therefore no more instructions regarding this)

Then you inspect your UIImageView, set your desired image you want to display and choose as view mode Aspect Fill

That way your UIImageView takes the image and scales it up, keeping it aspect ratio while filling its entire content.



来源:https://stackoverflow.com/questions/30001169/truly-universal-ios-launch-screen-using-launch-screen-xib-template

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