Is there any way to add subview in the "bottom" of its view,like z=0 when you use layers? I need this because when I spawn objects they need to be under another pictures,not above.
Asked
Active
Viewed 5,341 times
3 Answers
19
The subviews of a UIView are sorted in a way that the last one of the array is the frontmost one, and then the first one (index 0) is the one in the back. So, to insert it in the "bottom", it's sufficent to do like this:
[view insertSubview:aView atIndex:0]

Nicola Miotto
- 3,647
- 2
- 29
- 43
4
Sure thing--just add the new view and use the sendSubviewToBack: method of the container view.

sgress454
- 24,870
- 4
- 74
- 92
-
It's ok, if the View is ALREADY in hierarchy! But if you add view it's probably better to use [view insertSubview:aView atIndex:0] – Paweł Brewczynski Dec 26 '14 at 12:27
2
sendSubviewToBack:
Moves the specified subview so that it appears behind its siblings.
- (void)sendSubviewToBack:(UIView *)view

mvds
- 45,755
- 8
- 102
- 111