Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-c adding Subviews to the bottom of view

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.

like image 769
Mathemage Avatar asked Jul 19 '12 20:07

Mathemage


3 Answers

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]
like image 149
Nicola Miotto Avatar answered Nov 11 '22 16:11

Nicola Miotto


Sure thing--just add the new view and use the sendSubviewToBack: method of the container view.

like image 31
sgress454 Avatar answered Nov 11 '22 14:11

sgress454


sendSubviewToBack:

Moves the specified subview so that it appears behind its siblings.
- (void)sendSubviewToBack:(UIView *)view

source: http://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html

like image 37
mvds Avatar answered Nov 11 '22 16:11

mvds