2

How can I add a subview to the second to highest position on the stack? That is, say I have 3 subviews, with number 3 being the visible on top. How can I add a new view that is directly below that one and push the rest down?

Thanks!

  • Have you tried this? http://stackoverflow.com/questions/10051514/how-can-i-insert-a-subview-below-the-other-subviews – serverpunk May 21 '14 at 18:55

2 Answers2

2

Lets assume you have 3 subviews on your parentView. after adding all the subviews call this method-

[parentView insertSubview:yourView atIndex:parentView.subviews.count-1]

there are also other simpler methods such as

[parentView insertSubview: aboveSubview: ]
[parentView insertSubview: belowSubview: ]

Cheers , hope this helps !

NavinDev
  • 995
  • 1
  • 7
  • 8
0

There is this API:

insertSubview:newView belowSubview:oldView

didn't see it when I first looked at the documentation :)

BUT, if we didn't have a reference to out previous view, does anyone know a way we could get the last subview?