Coming from UIKit I discover it struggling to attain desired ends in SwiftUI. I assume I’m to caught within the constraint pushed format to get my head across the SwiftUI method.
Assume the next format:
-
On gadgets with a “common” display screen the horizontal area needs to be break up 1:1 right into a high and backside half.
-
The highest container maintain three views with mounted top which needs to be positioned on the high, heart and backside of the container.
-
The three views have some minimal spacing, e.g. 20px. If sufficient area is offered the spacing might be extra however by no means under 20px.
-
On smaller gadgets the highest container can shrink as much as a sure stage. However by no means so small, that the mounted width of the subviews and their spacing could be violated. On this case the ration between the highest and backside container wouldn’t be 1:1 anymore however e.g. 2:3.
-
On bigger gadgets like an iPad the highest container would solely develop as much as some max. top. On this case the ration between high and backside container would additionally not be 1:1 any extra.
-
The underside container view holds just one view which ought to at all times fill the obtainable area.
Fixing this utilizing constraints in UIKit could be no downside. I’m conscious that “common”, “smaller” and “greater” gadgets aren’t any precise measurement courses. That is only for illustration.
However how would this be solved in SwiftUI?
The fundamental format is in fact straight ahead:
VStack(spacing: 0) {
VStack {
TopView()
Spacer()
CenterView()
Spacer()
BottomView()
}
.body(maxWidth: .infinity, maxHeight: .infinity)
.background(.crimson)
VStack {
FillView()
}
.body(maxWidth: .infinity, maxHeight: .infinity)
.background(.inexperienced)
}
However the way to obtain the min- and maxHeight of the top-container? Is it potential to do that with out utilizing a GeometryReader
however solely with relative values?
The way to keep away from shrinking the highest container under a given min-height when the underside container turns into to large attributable to its content material?