Skip to content

Instantly share code, notes, and snippets.

@noppefoxwolf
Created September 3, 2023 11:09
Show Gist options
  • Save noppefoxwolf/2b8020265251349e7ca96c7fd13b1af2 to your computer and use it in GitHub Desktop.
Save noppefoxwolf/2b8020265251349e7ca96c7fd13b1af2 to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
var body: some View {
SquareLayout {
Button {
} label: {
Color.green
.frame(width: 320, height: 640)
}
}.clipped()
}
}
struct SquareLayout: Layout {
func sizeThatFits(
proposal: ProposedViewSize,
subviews: Subviews,
cache: inout ()
) -> CGSize {
CGSize(
width: 100,
height: 100
)
}
func placeSubviews(
in bounds: CGRect,
proposal: ProposedViewSize,
subviews: Subviews,
cache: inout ()
) {
let size = ProposedViewSize(
width: 100,
height: 100
)
subviews[0].place(
at: .zero,
proposal: size
)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment