Search code examples
iosuiviewz-index

ios change subview index runtime


i intend to do some menu with tabs,

if I have the tabs ordered with z index, and i insert each tab with:

insertSubview:(UIView *) atIndex:(NSInteger)

and by pressing a button on top of them I want to change the tab shown, on top

how can I change the subview index at runtime?

thanks!


Solution

  • sendSubviewToBack: and bringSubviewToFront: are the methods you are looking for. Another possibility is exchangeSubviewAtIndex:withSubviewAtIndex: if you want to exchange the layer of two views.