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

SteBra
  • 4,188
  • 6
  • 37
  • 68

4 Answers4

30

Just put it there directly instead.

[self.view insertSubview:_map atIndex:0];
Robert Gummesson
  • 5,630
  • 2
  • 17
  • 16
11

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

[self.view sendSubviewToBack:yourView];
rcat24
  • 548
  • 2
  • 23
8

Swift 3

Swift 4

view.insertSubview(view, at: 0)

Vyacheslav
  • 26,359
  • 19
  • 112
  • 194
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.

riyaz
  • 1,093
  • 1
  • 8
  • 21