Last active
July 18, 2024 21:29
-
-
Save don1138/697f5fd271a06df4cabbbfb4e12f0157 to your computer and use it in GitHub Desktop.
Use percentage widths on SwiftUI layout objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get screen width and subtract Safe Area margins | |
var containerWidth:CGFloat = UIScreen.main.bounds.width - 32.0 | |
// Set frame width of each column using (containerWidth * percentage) | |
HStack (spacing:0) { | |
HStack { | |
Text("Column 25% Width") | |
} | |
.frame(width: containerWidth * 0.25) | |
HStack { | |
Text("Column 25% Width") | |
} | |
.frame(width: containerWidth * 0.25) | |
HStack { | |
Text("Column 50% Width") | |
} | |
.frame(width: containerWidth * 0.5) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you, that helped me a lot!