How To Bring A View Forward Or Back In Swift Programmatically

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 and want to learn more, check out The Complete iOS Developer Bootcamp. Speed up your learning curve - hundreds of students have already joined. Thanks for reading!
Profile Picture of Eddy Chung

Eddy Chung

I teach iOS development on ZeroToAppStore.com.

Similar Posts