Created
September 3, 2023 11:09
-
-
Save noppefoxwolf/2b8020265251349e7ca96c7fd13b1af2 to your computer and use it in GitHub Desktop.
This file contains 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
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