Skip to content

Instantly share code, notes, and snippets.

@YusukeHosonuma
Created December 3, 2022 04:56
Show Gist options
  • Save YusukeHosonuma/8bbc0ba78665dc78a6169c60e89579b6 to your computer and use it in GitHub Desktop.
Save YusukeHosonuma/8bbc0ba78665dc78a6169c60e89579b6 to your computer and use it in GitHub Desktop.
SwiftUI: minXxx / maxXxx / fixedSize
struct ContentView: View {
var body: some View {
VStack(spacing: 50) {
// minWidth / minHeight
Color.blue.opacity(0.3)
.frame(minWidth: 100, minHeight: 200)
.frame(width: 150, height: 150)
.border(.black)
.overlay {
Text("min")
}
// maxWidth / maxHeight
Color.red.opacity(0.3)
.frame(maxWidth: 100, maxHeight: 200)
.frame(width: 150, height: 150)
.border(.black)
.overlay {
Text("max")
}
// fixedSize
ZStack {
Color.clear
.frame(width: 10, height: 10)
.border(.black)
Color.green.opacity(0.3)
.fixedSize()
.overlay(alignment: .bottom) {
Text("Color has not ideal size.\nRender as system default size. (10x10)")
.fixedSize()
.alignmentGuide(VerticalAlignment.bottom) { _ in -10 }
}
}
}
}
}
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