Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically send to front/back elements created from interface builder

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.

like image 650
Yohann T. Avatar asked Jun 28 '09 13:06

Yohann T.


1 Answers

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

  • bringSubviewToFront:
  • sendSubviewToBack:
  • insertSubview:atIndex:
  • insertSubview:aboveSubview:
  • insertSubview:belowSubview:
  • exchangeSubviewAtIndex:withSubviewAtIndex:

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

like image 89
Sebastian Celis Avatar answered Sep 20 '22 21:09

Sebastian Celis