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.
HStack :
Arrange the elements in the horizontal, if your have two element inside the HStack then it's arrange in Horizontally.
ZStack :
Arrange the elements in the Z index, if you have two element inside the ZStack then first element is below the second element.
Thanks
VStack :
Arrange the elements in the vertically, if your have two element inside the VStack then it's arrange in vertical.
123456789VStack {
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.
123456789HStack {
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.
123456789ZStack {
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?
Reviewed by KIRIT MODI
on
00:28:00
Rating:
