← 메인으로

0818-1 스위프트 예제 실습

Pasted image 20250818093255.png

인공지능 전혀 없이 직접 로직을 구현했다.

import SwiftUI struct ContentView: View { @State private var rotation: Double = 0 @State private var text: String = "Welocome to SwiftUI" @State private var colorIndex = 0 var colors: [Color] = [.red, .orange, .green, .blue, .pink] var colorNames = ["Red", "Orange", "Green", "Blue", "Pink"] var body: some View { VStack { Rectangle() .frame(width: 100, height: 100) .foregroundColor(colors[colorIndex]) .rotationEffect(Angle(degrees: rotation)) .animation(.easeInOut(duration: 5), value: rotation) Text(text) .font(.largeTitle) .fontWeight(.bold) Divider() Spacer() Slider(value: $rotation, in: 0 ... 360, step: 0.1) TextField("Enter your name", text: $text) .textFieldStyle(RoundedBorderTextFieldStyle()) Picker(selection: $colorIndex, label: Text("Color")) { ForEach(0 ..< colorNames.count, id: \.self) { color in Text(colorNames[color]) .foregroundColor(colors[color]) } } .pickerStyle(.wheel) } .padding(20) } } #Preview { ContentView() }