SwiftUI - 버튼 돌리기

김시온·2021년 5월 5일
0

Swift

목록 보기
5/8


import SwiftUI

struct ContentView: View {
    @State var isPressed = false
    var body: some View {
        HStack {
            Button(action: {
                isPressed.toggle()
            }) {
                Text("+")
                    .font(.largeTitle)
                    .padding()
                    .foregroundColor(.white)
                    .background(Color.green)
                    .clipShape(Circle())
                    .overlay(
                        Circle()
                            .stroke(Color.purple, lineWidth: 5)
                    )
            }
            .rotationEffect(isPressed ? Angle(degrees: 45) : .zero)
            .animation(.linear)

            Text("Spin!")
                .font(.body)
                .fontWeight(.black)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

0개의 댓글