TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Advanced Geometry?

Forums > SwiftUI

Hi, I have a Geometry to align two HStacks vertically.

The second row of my VStack has three individual returns. I separated them as separate elements so I can align them vertically.

If I make all three variables as one element so I can apply a modifier, is it still possible to align them vertically?

Or vice versa?

The second row which has the "deriveVibration" function has three variables V, C, and T which has diferrent result as the variables on top deriveV, deriveC, and deriverawTotal.

How do I apply this modifier? Text(deriveVibration(string: self.profile.name)) .font(.largeTitle) { if Text(deriveT(string: self.profile.name)) = 4, 6, or 8 { .foregroundColor(Color.Green) } else .foregroundColor(Color.White) }

Thank you for any suggestions you may have.

My current code below is set as one element. How can I align them individually without breaking them apart?

   GeometryReader { proxy in
 VStack(spacing: 0) {
    HStack {
        Text(deriveVowels(string: self.profile.name))
        Text(deriveConsonants(string: self.profile.name))
        Text(deriveRawTotal(string: self.profile.name))
            }
            .font(.headline)
            .frame(width: proxy.size.width * 0.04, alignment: .top) .fixedSize()
        Text(deriveVibration(string: self.profile.name))
            .font(.largeTitle)
            }
            .frame(width: proxy.size.width * 1, alignment: .top) .fixedSize()
            .foregroundColor(Color.white)
            .multilineTextAlignment(TextAlignment.center)
            }
         .frame(idealWidth: 8, maxHeight: 88)

3      

Did you try using an alignment parameter on your HStack?

HStack(alignment: .top) {
...
}

3      

Yes, it didn't change anything. I should mention that the top row is a smaller size than the bottom row and the top row could show a two digit per box whereas the bottom will always have a single digit per box.

3      

Check out custom Alignment Guides. Very powerful, and simple to use!

https://www.hackingwithswift.com/books/ios-swiftui/how-to-create-a-custom-alignment-guide

There's also a great video from WWDC2019 'Building Custom Views in SwiftUI', which demonstrates custom alignment guides starting at about the 20m50s mark:

https://developer.apple.com/videos/play/wwdc2019/237/

3      

Thank you, I will look into this.

3      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn 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.