Specifying z-order (sendSubviewToBack, etc.) on UIStackView
Asked Answered
S

1

9

According to the Apple docs:

The order of the subviews array defines the Z-order of the subviews. If the views overlap, subviews with a lower index appear behind subviews with a higher index.

I can see that this is the case, as I am trying to have its arrangedSubviews manually reordered using sendSubviewToBack, which is having no effect. How can I adjust the z-order of the arrangedSubviews in a UIStackView?

Screamer answered 8/8, 2016 at 13:39 Comment(1)
See the answer here https://mcmap.net/q/517252/-overlapping-views-in-uistackviewCommitment
O
11

Use this!

yourArrangedSubview.layer.zPosition = xxx

Overmatch answered 11/7, 2018 at 16:46 Comment(2)
This seems to work, but it seems to be undocumented behavior. On which iOS versions will work? will it break in the future? I wouldn't rely on this except for cosmetic changes that you are OK might break at some point.Eat
Hard to say. I wrote this answer several years ago. Seems to still be working nicely. I would imagine as long as UIStackView and UIView don't change too dramatically, this should work.Overmatch

© 2022 - 2024 — McMap. All rights reserved.