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

Custom Layouts that specify both height and width

Forums > SwiftUI

I have converted RelativeHStack from the Pro SwiftUI book to RelativeVStack, and both are working independently. However, I need my subviews to have frames that are relative to the parent view size in both directions. So if the height is 50% of the parent's height, the width should be 50% of the parent's width. I can't get this to work; specifying fixed sizes for both height and width to the call to ProposedViewSize results in unexpected and unexplainable (by me, anyway) results.

I've searched for other custom layout examples and it seems like all of them specify either width or height and allow the other dimension to be flexible, which generally means that the subviews are hugging their content. Am I trying to do something that SwiftUI doesn't support? If not, can someone please explain or point me to an example? Thanks in advance!

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.