0

My view contains an area on the bottom. I want to make it fill the 0.3 times of the screen height. However, if the UIScreen is deprecated, I cannot get the screen size on newer versions of iOS. Additionally, if I use GeometryReader, my screen breaks. I am new to SwiftUI and I believe there is another way to work with these type of situations rather than hardcoding the size. Any help is appreciated.

For example:

Button {
    onButtonPressed()
} {
    Text("Press Me")
}
.frame(
    maxWidth: .infinity,
    maxHeight: UIScreen.main.bounds.height * 0.3 // Can not do that anymore
)
Subfly
  • 492
  • 2
  • 13
  • 1
    It is impossible to help more specifically since you haven't provided a sample but hardcoded values are not needed with SwiftUI use alignments, aspectRatio, Spacers, frame with max/min width/height, ScaledMetric, etc. GeometryReader allows for use of percentages, there is no way around that but it is phasing out too the new `Layout` is the new alternative. – lorem ipsum Dec 10 '22 at 15:47
  • @loremipsum I have added an example code. What I mean is If I want to make that button hold up space exactly 0.3 times of the screen height, how can I do? There must be a simple way such as using UIScreen rather than using the GeometryReader. – Subfly Dec 10 '22 at 15:54
  • I get what you are seeking/saying, GeometryReader or Layout are the SwiftUI ways of doing this `UIScreen.main.bounds.height` is the "easy" way but not very SwiftUI-ish it is very brute-force – lorem ipsum Dec 10 '22 at 16:02

0 Answers0