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

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,

1      

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.

1      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.