Programmatically send to front/back elements created from interface builder

亡梦爱人 提交于 2019-12-17 10:12:28

问题


In interface builder, there are layout options to send to back or send to front any elements such as UIButton, UIImage, UILabel etc...

Now, I would like to do the same at runtime, programmatically.

Is there an easy way to do that?

I do not want to create different views, just update the z-axis.


回答1:


There are a number of methods of UIView that allow you to modify the view hierarchy.

  • bringSubviewToFront:
  • sendSubviewToBack:
  • insertSubview:atIndex:
  • insertSubview:aboveSubview:
  • insertSubview:belowSubview:
  • exchangeSubviewAtIndex:withSubviewAtIndex:

Since your views are already inserted into your superview, you could easily call bringSubviewToFront: once for each view in whatever order you like.




回答2:


You could use:

[self.view bringSubviewToFront:myButton];


来源:https://stackoverflow.com/questions/1054937/programmatically-send-to-front-back-elements-created-from-interface-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!