UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Project 6 challenges troubles

Forums > 100 Days of Swift

Hi to all, I'm trying to solve the challenges in project 6

https://www.hackingwithswift.com/read/6/6/wrap-up

The first was quite easy (Try replacing the widthAnchor of our labels with leadingAnchor and trailingAnchor constraints, which more explicitly pin the label to the edges of its parent.)

I'm not sure to understand what "try using the safeAreaLayoutGuide for those constraints" means

The third challeng is really hard: Try making the height of your labels equal to 1/5th of the main view, minus 10 for the spacing.

After half an hour of obscure coding I've read the hint, so I tried

label.heightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.heightAnchor, multiplier: 0.5, constant: 10)

but the results is not what I expected to be...

Any hint?

4      

Looks like nobody solved these challenges... 🤔

3      

1/5th is 0.2 not 0.5

Make that change and see if you get what you expect.

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

I think he wants you to use the safeAreaLayoutGuide to the the spacing on the sides in landscape mode. As for the one fifth, 1/5 = 0.2, as noted in the above comment.

3      

Thanks for your answers but changing that value doesn't change anything, visually talking... I'm sure that I miss something but I really can't understand what's the problem... I think I'll try to follow again the entire project videos...

3      

I just did that exercise half an hour ago and had the same problem as you. After trying all kinds of combinations, I finally thought about what the constant is actually supposed to do... It adds space to your view. That is the opposite of what we want. We want to delete 10 points from the label and use that space for the white space between the labels. So... instead of constant: 10 we have to use constant: -10.

6      

Hi All I think I solved challenge 1 and 2 as well from this project from what I understood goes like this: Whe you guys will rotoate your device or / simulator than that label will not be streched fully on the whole screen, "so the label is pushed away from the top and bottom of the safe area, so it doesn’t sit under the notch". Hope it helps!

Note: If you guys don't add "safeAreaLayoutGuide" to these constraits the labels will be still streched out fully on the screen this is in challenge 1.

    for label in [label1, label2, label3, label4, label5] {

// label.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true -> this is the previous line what I've replaced

        label.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true 
        label.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true   
        label.heightAnchor.constraint(equalToConstant: 88).isActive = true

3      

label.heightAnchor.constraint(equalToConstant: view.frame.height/5).isActive = true

i just did this, but i dont know how to make it autoresize when its horizontal view.

3      

The solution for all 3 challenges:

for label in [label1, label2, label3, label4, label5] {
            label.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
            label.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true

            let spaceBetweenLabels = 10
            label.heightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.heightAnchor,
                                          multiplier: 0.2,
                                          constant: - spaceBetweenLabels).isActive = true
            // it🔝 means:
            // each label's height should be 1/5 or 0.2 OF THE safe area's height
            // minus space between labels

            if let previousLabel = previousLabel {
                label.topAnchor.constraint(equalTo: previousLabel.bottomAnchor, constant: 10).isActive = true
            } else {
                label.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
            }

            previousLabel = label
        }

2      

Thanks for sharing amazing information keep posting. sjolingbogren.se Thank you for such an amazing discussion.

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.