Programmatically send to front/back elements created from interface builder

Cocoa TouchInterface BuilderZ Axis

Cocoa Touch Problem Overview


In interface builder, there are layout options to send to back or send to front any elements such as UIButton, UIImage, UILabel etc...

Now, I would like to do the same at runtime, programmatically.

Is there an easy way to do that?

I do not want to create different views, just update the z-axis.

Cocoa Touch Solutions


Solution 1 - Cocoa Touch

There are a number of methods of UIView that allow you to modify the view hierarchy.

Since your views are already inserted into your superview, you could easily call bringSubviewToFront: once for each view in whatever order you like.

Solution 2 - Cocoa Touch

You could use:

[self.view bringSubviewToFront:myButton];

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionYohann T.View Question on Stackoverflow
Solution 1 - Cocoa TouchSebastian CelisView Answer on Stackoverflow
Solution 2 - Cocoa TouchhanumanDevView Answer on Stackoverflow