Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I insert a subview below the other subviews

everyone.

I have some labels that I draw them in the xib file, and add a background view using codes,but the background view is in the front of these labels, so I cant see them. So, my question is how can I add a background view below these labels.

Thank you in advance.

like image 258
jxdwinter Avatar asked Apr 07 '12 03:04

jxdwinter


3 Answers

If you Google UIView you'll end up at the documentation - UIView Class Reference

Then you need to look down the list of methods until you find something that sounds like it will roughly fit your needs like these two:

- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index

and

- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview

At this point you just have to read the descriptions of how the methods behave and pick whichever one is easiest to implement for your design. It's really good for your own learning if you try to find the answer yourself before you ask a question

like image 73
Paul.s Avatar answered Sep 21 '22 01:09

Paul.s


You can use the method insertSubview:atIndex:

[self.view insertSubview:backgroundView atIndex:0];
like image 20
sch Avatar answered Sep 23 '22 01:09

sch


You can call this method in Swift 3

view.insertSubview(yourSubView, at: 0)

or

view.sendSubview(toBack: yourSubView)
like image 6
Kwaku Eshun Avatar answered Sep 21 '22 01:09

Kwaku Eshun