-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from SOPT-all/week4-Semin
[4주차] 이세민 실습
- Loading branch information
Showing
10 changed files
with
469 additions
and
2 deletions.
There are no files selected for viewing
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
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
42 changes: 42 additions & 0 deletions
42
LeeSeminSU/LeeSeminSU/Week4/Navigation/FirstNavigationViewExample.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// FirstNavigationViewExample.swift | ||
// LeeSeminSU | ||
// | ||
// Created by 이세민 on 12/5/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct FirstNavigationViewExample: View { | ||
var body: some View { | ||
NavigationView { | ||
VStack { | ||
Text("첫 번째 화면") | ||
.font(.largeTitle) | ||
.padding() | ||
|
||
NavigationLink(destination: SecondNavigationViewExample()) { | ||
Text("두 번째 화면으로 이동") | ||
.padding() | ||
.background(Color.blue) | ||
.foregroundColor(.white) | ||
.cornerRadius(10) | ||
} | ||
} | ||
.navigationBarTitle("첫 번째 화면", displayMode: .inline) | ||
.navigationBarItems(leading: Button(action: { | ||
print("검색 버튼 클릭") | ||
}) { | ||
Image(systemName: "magnifyingglass") | ||
}, trailing: Button(action: { | ||
print("공유 버튼 클릭") | ||
}) { | ||
Image(systemName: "square.and.arrow.up") | ||
}) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
FirstNavigationViewExample() | ||
} |
21 changes: 21 additions & 0 deletions
21
LeeSeminSU/LeeSeminSU/Week4/Navigation/SecondNavigationViewExample.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// SecondNavigationViewExample.swift | ||
// LeeSeminSU | ||
// | ||
// Created by 이세민 on 12/5/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct SecondNavigationViewExample: View { | ||
var body: some View { | ||
Text("두 번째 화면") | ||
.font(.largeTitle) | ||
.padding() | ||
.navigationBarTitle("두 번째 화면", displayMode: .inline) | ||
} | ||
} | ||
|
||
#Preview { | ||
SecondNavigationViewExample() | ||
} |
53 changes: 53 additions & 0 deletions
53
LeeSeminSU/LeeSeminSU/Week4/SheetModifier/SheetModifierExample.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// SheetModifierExample.swift | ||
// LeeSeminSU | ||
// | ||
// Created by 이세민 on 12/5/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct SheetModifierExample: View { | ||
@State private var showModal = false // 모달을 보여줄지 말지를 결정하는 상태 변수 | ||
@State private var name = "" | ||
|
||
var body: some View { | ||
VStack { | ||
Text("나의 이름은") | ||
.font(.title) | ||
TextField("이름을 입력하세요.", text: $name) | ||
.textFieldStyle(RoundedBorderTextFieldStyle()) | ||
.padding() | ||
|
||
Button("모달 열기") { | ||
showModal.toggle() | ||
} | ||
.sheet(isPresented: $showModal) { | ||
ModalView(name: name) // 입력된 이름을 모달에 전달 | ||
} | ||
.padding() | ||
} | ||
.padding() | ||
} | ||
} | ||
|
||
struct ModalView: View { | ||
var name: String // 전달받은 이름 | ||
@Environment(\.dismiss) var dismiss // 모달을 닫을 때 사용 | ||
|
||
var body: some View { | ||
VStack { | ||
Text("안녕 \(name)?") | ||
.font(.title) | ||
Button("닫기") { | ||
dismiss() | ||
} | ||
.padding() | ||
} | ||
.padding() | ||
} | ||
} | ||
|
||
#Preview { | ||
SheetModifierExample() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// BindingExample.swift | ||
// LeeSeminSU | ||
// | ||
// Created by 이세민 on 12/5/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct BindingExample: View { | ||
@State private var sliderValue: Double = 50 | ||
|
||
var body: some View { | ||
VStack { | ||
SliderView(value: $sliderValue) | ||
Text("Value: \(Int(sliderValue))") | ||
.font(.headline) | ||
} | ||
.padding() | ||
} | ||
} | ||
|
||
struct SliderView: View { | ||
@Binding var value: Double | ||
|
||
var body: some View { | ||
Slider(value: $value, in: 0...100) | ||
.padding() | ||
} | ||
} | ||
|
||
#Preview { | ||
BindingExample() | ||
} |
101 changes: 101 additions & 0 deletions
101
LeeSeminSU/LeeSeminSU/Week4/State/EnvironmentObjectExample.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// | ||
// EnvironmentObjectExample.swift | ||
// LeeSeminSU | ||
// | ||
// Created by 이세민 on 12/5/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
// 테마 색상 모델 | ||
class ThemeModel: ObservableObject { | ||
@Published var themeColor: Color = .black | ||
|
||
func changeThemeColor(to color: Color) { | ||
themeColor = color | ||
} | ||
} | ||
|
||
struct EnvironmentObjectExample: View { | ||
@EnvironmentObject var themeModel: ThemeModel // 전역 상태로 테마 색상 사용 | ||
|
||
var body: some View { | ||
VStack { | ||
Text("현재 색상") | ||
.font(.title) | ||
.foregroundColor(themeModel.themeColor) // 테마 색상 적용 | ||
.padding() | ||
|
||
Button(action: { | ||
themeModel.changeThemeColor(to: .red) | ||
}) { | ||
Text("Red Theme") | ||
.padding() | ||
.background(Color.red) | ||
.foregroundColor(.white) | ||
.cornerRadius(8) | ||
} | ||
.padding() | ||
|
||
Button(action: { | ||
themeModel.changeThemeColor(to: .orange) | ||
}) { | ||
Text("Orange Theme") | ||
.padding() | ||
.background(Color.orange) | ||
.foregroundColor(.white) | ||
.cornerRadius(8) | ||
} | ||
.padding() | ||
|
||
Button(action: { | ||
themeModel.changeThemeColor(to: .yellow) | ||
}) { | ||
Text("Yellow Theme") | ||
.padding() | ||
.background(Color.yellow) | ||
.foregroundColor(.white) | ||
.cornerRadius(8) | ||
} | ||
.padding() | ||
|
||
Button(action: { | ||
themeModel.changeThemeColor(to: .green) | ||
}) { | ||
Text("Green Theme") | ||
.padding() | ||
.background(Color.green) | ||
.foregroundColor(.white) | ||
.cornerRadius(8) | ||
} | ||
.padding() | ||
|
||
Button(action: { | ||
themeModel.changeThemeColor(to: .blue) | ||
}) { | ||
Text("Blue Theme") | ||
.padding() | ||
.background(Color.blue) | ||
.foregroundColor(.white) | ||
.cornerRadius(8) | ||
} | ||
.padding() | ||
} | ||
.padding() | ||
} | ||
} | ||
|
||
struct EnvironmentObjectContentView: View { | ||
// @StateObject로 테마 모델 생성 | ||
@StateObject private var themeModel = ThemeModel() | ||
|
||
var body: some View { | ||
// 테마 색상을 여러 뷰에서 사용 가능하도록 전달 | ||
EnvironmentObjectExample() | ||
.environmentObject(themeModel) | ||
} | ||
} | ||
|
||
#Preview { | ||
EnvironmentObjectContentView() | ||
} |
Oops, something went wrong.