Ray Wenderlich Course - SwiftUI (Part 4)

Lots going on at the moment but I am going to squeeze in a session today. Next bit of SwiftUI!

Start Time - 19:32

Second Section: Building Interfaces with Container Views

So stacks in detail and using bits from Swift UIKit. Tab views coming up as well.

HStack, VStack and ZStack

A mention of alignments - leading is left and trailing is right.

Different alignments to the centre default - first/last baseline alignment

ZStack is different - you have elements on top of one another.

So the whole right click and embed in V or H Stack means that this puts what you have within another stack. Makes sense.

Here is what we have at the moment....

VStack {
        HStack {
            
            Image("CatOnKeyboard")
                .resizable()
                .frame(width: 50, height: 50)
            
            Button(action: {
                
                
            }) {
                HStack {
                    Text("Sign up now!")
                    Image(systemName: "checkmark.circle")
                }
                
            }
          .padding()
          .background(Color.catPurple)
          .foregroundColor(.white)
            .shadow(radius: 5)
        }
    }
    }

}


Simple and effective so far!

ZStack {
        
        Circle()
            .fill(Color.catPurple)
        
        VStack {
            Image("CatOnKeyboard")
            .resizable()
                .frame(width: 150, height: 150)
            
            Text("Help for cats!")
                .font(Font.system(.largeTitle, design: .rounded))
                .foregroundColor(.pink)
                .fontWeight(.heavy)
            .shadow(radius: 5)
            
        }
        Spacer()
        .layoutPriority(1)
        
    }
    .background(Color.rayWenderlichGreen)
    .edgesIgnoringSafeArea(.all)
    
    }
}


I'm really enjoying this! This time it is a ZStack which has things on top of one another. Very cool. 

How the Layout System Works

So constraints are still used...

The ambiguous constraints are a thing of a past however! Woohoo - that was such a pain with Swift UIKit. 

So you have Root View, then Control View, then whatever objects you have. 

So there is never a conflict with views - getting confusing or weird layouts. 

There is flexibility with components. Text has quite a lot but images - as they come from a different source - show the actual size and have little wriggle room. 

Between multiple objects, Xcode will go to the least flexible first, then the next and so on. Then divide the padding space between the number of objects. 

There is a layout priority too. You can put in a minimus scale factor and aspectRatio for an image. So making the least flexible the one you want to take priority!

If you specify a height/dimension then this is non-negotiable. 

You can put in nil or .infinity for the min/max sizes of the frame - this gives more flexibility. 

So a lot of info on this one - nothing practical to play with but the auto layout is a real paradigm shift! I agree with Laurie that the pay offs will be huge. Much better than UIKit!

Finish Time - 20:26 (54 minutes)

So again great stuff! I like Laurie's explanations. They're relatable and interesting. I'm definitely going to see this course through now - I have a lot more knowledge already. 

Comments

Popular posts from this blog

*Xcode Project Entry 2* F1 Quiz - part 1

Angela Yu Course Part 10 (up to lesson 112)

Angela Yu Xcode 12 Course - Part 7 (lectures 74 to 79)