WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: Day 56 - CHALLENGE : Offset coordinates

Forums > 100 Days of SwiftUI

With the challenge to overlay the formatted Date on the detailsView, I'd like to place the date on the top left of the screen. According to previous videos & apple's docs, the coordinates (0,0) start on the top left of the screen. However the two capsule shapes have offsets (-5,-5) and (0,0) and yet they appear on the bottom right of the image.

Imgur

Why is this? Can someone explain how this makes sense and what I need to do to get the capsules at the top right.

Thanks,

   

The ZStack has an alignment of bottomTrailing so the Text element gets shoved down into the bottom right corner. The offset modifier then adjusts the position by the given number of pixels.

offset doesn't indicate absolute coordinates where something is located but the amount of shift from wherever the item is located. .offset(x: -5, y: -5) shifts an item to the left and up from wherever it is positioned.

   

Hacking with Swift is sponsored by Emerge

SPONSORED Optimize your app’s startup time, binary size, and overall performance using Emerge’s advanced app optimization and monitoring tools. Reliably measure app size, speed up your app's startup time with Emerge's Launch Booster, and much more. Emerge is actively used by many of the top mobile development teams in the world.

Find out more

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

Reply to this topic…

You need to create an account or log in to reply.

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.