SteBra
SteBra

Reputation: 4247

How to addSubview to the bottom of view hierarchy

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 ?!

Upvotes: 19

Views: 15378

Answers (4)

Vyacheslav
Vyacheslav

Reputation: 27211

Swift 3

Swift 4

view.insertSubview(view, at: 0)

Upvotes: 8

riyaz
riyaz

Reputation: 1103

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.

Upvotes: 2

Robert Gummesson
Robert Gummesson

Reputation: 5666

Just put it there directly instead.

[self.view insertSubview:_map atIndex:0];

Upvotes: 30

rcat24
rcat24

Reputation: 538

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

[self.view sendSubviewToBack:yourView];

Upvotes: 11

Related Questions