15.3 C
Canberra
Tuesday, October 21, 2025

HStack, VStack, and ZStack – iOSTutorialJunction


If you’re designing your iOS app with SwiftUI, it’s important to grasp the fundamental ideas of Stacks, significantly HStack, VStack, and ZStack, and how one can use them. On this tutorial, we’ll discover these three sorts of stacks.

HStack

HStack – H in HStack stands for Horizontal. This stack view arranges all the weather/views inside it horizontally. Under picture has a HStack and contained in the HStack we have now 2 Textual content labels.

HStack, VStack, and ZStack – iOSTutorialJunction
HStack {
  Textual content ("Good day" )
  .font(.title)
  .background (.yellow)
               
  Textual content ("World!")
  . font(.title)
 .background (.inexperienced)
}
 . padding()
 .background (.crimson)

VStack

VStack – V in VStack stands for Vertical. This stack will organize all the weather/views inside it vertically. Under picture is having a VStack and you’ll clearly see that it arranges views vertically slightly than horizontally(which was the case once we used HStack)

Views added to VStack
VStack {
  Textual content ("Good day" )
  .font(.title)
  .background (.yellow)
               
  Textual content ("World!")
  .font(.title)
 .background (.inexperienced)
}
 . padding()
 .background (.crimson)

ZStack

ZStack – This stack view is completely different from each HStack and Vstack. After we add views to this ZStack, it aligns view on high of one another. Although we will change the looks order of added views by giving them z-index worth. Greater z-axis worth than the one earlier than it, means later sub-view seem “on high” of earlier ones.

ZStack containing rectangles of different colors

Abstract

On this submit, we find out about various kinds of stacks utilized in SwiftUI, i.e. HStack is used to position view horizontally, VStack is used to position views vertically and ZStack is used once we need views on high of one another inside a container view. Since stacks are the fundamental constructing block whereas we design iOS app utilizing SwiftUI so we have to have fundamental understanding of those 3 stack views.



Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles