SwiftUI - What's Different between VStack, HStack and ZStack?

Th Stack is equivalent to UIStackView in UIKit. Stack is use to arrange elements horizontal, vertical and depth.



VStack : 
Arrange the elements in the vertically, if your have two element inside the VStack then it's arrange in vertical.
VStack {
    RoundedRectangle(cornerRadius: 10)
        .fill(Color.yellow)
        .frame(width: 80, height: 80)

    RoundedRectangle(cornerRadius: 10)
        .fill(Color.red)
        .frame(width: 80, height: 80)
}



HStack : 
Arrange the elements in the horizontal, if your have two element inside the HStack then it's arrange in Horizontally.
HStack {
    RoundedRectangle(cornerRadius: 10)
        .fill(Color.yellow)
        .frame(width: 80, height: 80)

    RoundedRectangle(cornerRadius: 10)
        .fill(Color.red)
        .frame(width: 80, height: 80)
}

ZStack : 
Arrange the elements in the Z index, if you have two element inside the ZStack then first element is below the second element.
ZStack {
    RoundedRectangle(cornerRadius: 10)
        .fill(Color.yellow)
        .frame(width: 200, height: 200)

    RoundedRectangle(cornerRadius: 10)
        .fill(Color.red)
        .frame(width: 80, height: 80)
}



Thanks
SwiftUI - What's Different between VStack, HStack and ZStack? SwiftUI - What's Different between VStack, HStack and ZStack? Reviewed by KIRIT MODI on 00:28:00 Rating: 5

1 comment:

  1. If you're looking to lose pounds then you absolutely have to start following this brand new personalized keto meal plan.

    To create this service, licenced nutritionists, personal trainers, and cooks joined together to develop keto meal plans that are useful, convenient, money-efficient, and satisfying.

    From their launch in January 2019, thousands of individuals have already completely transformed their figure and well-being with the benefits a professional keto meal plan can provide.

    Speaking of benefits: clicking this link, you'll discover 8 scientifically-proven ones provided by the keto meal plan.

    ReplyDelete

Powered by Blogger.