So, as far as I can tell, alignment guides can't be used in this way – yet. Hopefully this will be coming soon, but in the meantime we can do a little padding trickery to get the desired effect.
- You will need to have some way of retrieving the font metrics – I'm using
CTFont
to initialise myFont
instances and retrieving metrics that way. - As far as I can tell, Playgrounds aren't always representative of how a SwiftUI layout will be laid out on the device, and certain inconsistencies arise. One that I've identified is that the
displayScale
environment value (and the derivedpixelLength
value) is not set correctly by default in playgrounds and even previews. Therefore, you have to set this manually in these environments if you want a representative layout (FB7280058). - Significantly, the default text view height appears to differ between macOS and iOS. I have a calculation that works with most fonts on iOS, and here I've found a calculation for macOS that seems to work – but ideal