Skip to content

Instantly share code, notes, and snippets.

@vadimbelyaev
Created May 29, 2022 21:38
Show Gist options
  • Save vadimbelyaev/1d8236a896e07316569217548079cf1b to your computer and use it in GitHub Desktop.
Save vadimbelyaev/1d8236a896e07316569217548079cf1b to your computer and use it in GitHub Desktop.
Two ways of rounding corners in SwiftUI
import SwiftUI
struct ContentView: View {
@State private var isBeautiful = false
var body: some View {
VStack {
Spacer()
ZStack {
Text(".cornerRadius")
.foregroundColor(.white)
.frame(width: 200, height: 50)
.background { Color.blue }
.cornerRadius(24)
.opacity(isBeautiful ? 0 : 1)
Text(".clipShape")
.foregroundColor(.white)
.frame(width: 200, height: 50)
.background { Color.blue }
.clipShape(RoundedRectangle(
cornerRadius: 24,
style: .continuous))
.opacity(isBeautiful ? 1 : 0)
}
Spacer()
Button {
withAnimation(.easeInOut(duration: 1.0)) {
isBeautiful.toggle()
}
} label: {
Text("Toggle")
}
.padding()
}
}
}
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