SwiftUI - 버튼 돌리기

5760 단어 swiftuiswiftui


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()
    }
}

좋은 웹페이지 즐겨찾기