views:

2239

answers:

2

Hi,

In interface builder, there are layouts 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 play with the z-axis.

Thank you.

Yohann

+11  A: 

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.

Sebastian Celis
Are you saying that I can't directly send a UIButton to front/back? I have to create a view and add it to that view. Then use the methods above? If so, Is the controller class the place to create such a view?
Yohann T.
A UIButton is a subclass of UIView. Just call: [[myButton superview] bringSubviewToFront:myButton];
Sebastian Celis
Just tried it, works like a charm.Thank you for answering that fast.Correct answer.
Yohann T.
A: 

[self.view bringSubviewToFront:myButton];

hanumanDev