How to programmatically set the front / rear view?

I am working on an application that uses a UIView as the background for text. I put the views behind the text on the storyboard , but for some reason some still seem to be in front of the text. Is there a way to send these views backwards programmatically? Here is a screenshot of what he is talking about Picture

+5
source share
2 answers

You can use the following two:

 - (void)bringSubviewToFront:(UIView *)view; - (void)sendSubviewToBack:(UIView *)view; 

view.sendSubviewToBack(subview) and view.bringSubviewToFront(subview)

  • bringSubviewToFront: Moves the specified view so that it appears on top of its siblings.
  • sendSubviewToBack: Moves the specified view so that it is displayed behind its siblings.

https://developer.apple.com/reference/uikit/uiview?language=objc

+6
source

sendSubviewToBack API is what you want for this task.

Moves the specified preview so that it appears behind his brothers and sisters.

This method moves the specified view to the beginning of the array of views in the subviews property.

UIView class reference

The following is a snippet of code in Swift lang on how to call this API:

Swift

 yourSuperview.sendSubviewToBack(yourSubview) 
+1
source

All Articles