ZIndex is used to alter default overlapping order in layout views. View with higher zIndex value appears at the top. Default value for zIndex is zero.
When two views overlap, framework determines the order by zIndex value and if two values are same, views are placed in the order they appear in hierarchy.
At this point, we don’t have any zIndex defined so mint color is covered by orange and indigo colors. Let’s add zIndex for each but give mint a higher value.
Let’s update our view logic so we can dynamically change the zIndex for each of the rounded rect views. We will add three State variables and bind them to a Slider. We will use this Slider bound value as zIndex for RoundedRectangle view.
We saw example with ZStack but same is true for VStack as well. zIndex is applied on View so layout stack doesn’t matter. We can see that by changing our stack to VStack and updating offset values so views overlap.
With that we have reached the end of this article. Thank you once again for reading. Don’t forget to follow 😍. Also subscribe our newsletter at https://www.devtechie.com