Created
May 29, 2022 21:38
-
-
Save vadimbelyaev/1d8236a896e07316569217548079cf1b to your computer and use it in GitHub Desktop.
Two ways of rounding corners in SwiftUI
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 { | |
@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