0

in swift I'd like to programatically re-arranger the order of my control

by example I have a textview that is on top of another one and I'd like to change their orders in which they appear (send to back)ect

I looked hard online but can't find an answer to this

update:

I read the article linked but those solutions don't work in swift 4.0

Sarah linone
  • 43
  • 1
  • 7
  • Question not clear. Pls explain your requirement more clearly. – dahiya_boy Nov 21 '17 at 07:21
  • Possible duplicate of [How to set iPhone UIView z index?](https://stackoverflow.com/questions/4631878/how-to-set-iphone-uiview-z-index) – Tj3n Nov 21 '17 at 07:23
  • At daiydiumboy, you know how u can change their visible order in Xcode via the menu under view controler scene they appear in that order that they are in on that list so if the textfield is over a scroll view we will see the textfield and the scrollview will be hidden I want to this programaticly – Sarah linone Nov 21 '17 at 07:28

1 Answers1

0

You have following methods to manipulate which subview is above/behind other:

bringSubviewToFront(_:)
sendSubviewToBack(_:)
removeFromSuperview()
insertSubview(_:atIndex:)
insertSubview(_:aboveSubview:)
insertSubview(_:belowSubview:)
exchangeSubviewAtIndex(_:withSubviewAtIndex:)

If you need to know current index(z position) of subview, it corresponds to its index in superview.subviews array.

Predrag Samardzic
  • 2,661
  • 15
  • 18