Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Last active April 22, 2024 21:35
Show Gist options
  • Save benigumocom/6900760b525ab0b1b7975de5f236370f to your computer and use it in GitHub Desktop.
Save benigumocom/6900760b525ab0b1b7975de5f236370f to your computer and use it in GitHub Desktop.
【SwiftUI】How ro round rectangle 👉 https://android.benigumo.com/20240423/rounded-rectangle/
import SwiftUI
struct TestContainerShape: View {
var body: some View {
VStack {
Text("🐶 Dog")
.padding()
.background(.yellow)
.clipShape(.rect(cornerRadius: 24)) // *
.padding()
.background(.white)
.clipShape(.rect(cornerRadius: 24)) // *
Text("🐶 Dog")
.padding()
.background(.yellow)
.padding()
.containerShape(.rect(cornerRadius: 24)) // *
.background { // *
RoundedRectangle(cornerRadius: 24)
.fill(.background)
}
Text("🐶 Dog")
.padding()
.background(.yellow)
.padding()
.background(.white)
.containerShape(.rect(cornerRadius: 24)) // *
VStack {
Text("🐱 Cat")
.padding()
.background(.orange)
.padding()
.background(.white)
Text("🐭 Mouse")
.padding()
.background(.cyan)
.padding()
.background(.white)
}
.padding()
.background(.green)
.containerShape(.rect(cornerRadius: 40))
//.contentShape(.rect(cornerRadius: 40)) // no effect
//.clipShape(.rect(cornerRadius: 40)) // outer only
}
.padding()
.background(.blue)
}
}
#Preview("TestContainerShape") {
TestContainerShape()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment