How to addSubview to the bottom of view hierarchy
Asked Answered
A

4

19

I want to add mapView, which I'm adding programatically, to the bottom of hierarchy view, as I already draw some of the elements beforehand, in the storyboard.

So, after i call method:

[self.view addSubview:self.map];

How do I put it on the bottom of the view hierarchy ?!

Avaavadavat answered 26/1, 2015 at 13:24 Comment(1)
You can use - (void)insertSubview:(UIView *)view atIndex:(NSInteger)indexDowns
S
30

Just put it there directly instead.

[self.view insertSubview:_map atIndex:0];
Schmooze answered 26/1, 2015 at 13:47 Comment(0)
B
11

"This method moves the specified view to the beginning of the array of views in the subviews property."

[self.view sendSubviewToBack:yourView];
Ber answered 26/1, 2015 at 13:42 Comment(0)
W
8

Swift 3

Swift 4

view.insertSubview(view, at: 0)

Womenfolk answered 2/11, 2017 at 9:3 Comment(1)
How can you insert it at the absolute bottom of the screen for even the iPhone X (no safe zone)!?Seam
H
2

Answer by Robert and rcat24 does work. Alternatively,

You can use "zPosition"

subViewToBeOnTop.layer.zPosition=1.0;

subViewToBeOnBottom.layer.zPosition=.9;

1 being top most, 0 being least.

Hann answered 26/1, 2015 at 16:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.