How To Bring A View Forward Or Back In Swift Programmatically

By Eddy Chung

Bringing a view forward or back programmatically is a common task for iOS developers.

How To Bring A View Forward In Swift

To bring a view forward in Swift, call bringSubviewToFront:

view.bringSubviewToFront(childView)

You can also use the superView property to call this from the child view:

childView.superview?.bringSubviewToFront(childView)

How To Send A View Backward In Swift

To bring a send backward in Swift, call sendSubviewToBack:

view.sendSubviewToBack(childView)

Again, you can use the superView property to call this from the childview:

childView.superview?.sendSubviewToBack(childView)
If you liked this post, you'll love my free guide: Secrets To iOS Development. Speed up your learning curve - hundreds of students have already downloaded. Thanks for reading!
Profile Picture of Eddy Chung

Eddy Chung

I am a professional iOS developer in Silicon Valley. I teach iOS development on ZeroToAppStore.com. If you'd like to learn more about me click here or you can contact me at: eddy@zerotoappstore.com

Similar Posts