How to add a background image

2019-09-12 17:15发布

问题:

I have a Image View on my storyboard, and when I am trying to use it as a background. No matter what I do, it always stays on top. How would I change it so that it would be a background image, I don't care weather I do it programmatically through swift or through another way.

回答1:

By moving any of item up/down you can set their layer state. The first one will be on back then second will appear on the first one then.... last one will appear on top most.

I hope this will help you.



回答2:

In the Xcode Interface Builder, you can adjust which views are in the front by selecting the view and going to Editor -> Arrange -> Send to Front, Back, etc.

This can also be done programmatically using UIView methods like bringSubviewToFront:



回答3:

If you decide to do it programmatically, you can modify the zPosition property of the view:

myImageView.layer.zPosition = 1

Higher numbers are closer to your face, lower numbers are closer to the screen. So to set your image view as a background, make sure the other views have higher z-positions than it.