Skip to content

Commit

Permalink
Merge pull request #43 from SOPT-all/week4-Semin
Browse files Browse the repository at this point in the history
[4주차] 이세민 실습
  • Loading branch information
sem-git authored Dec 4, 2024
2 parents 1716ff8 + 377a6c6 commit 360c0c5
Show file tree
Hide file tree
Showing 10 changed files with 469 additions and 2 deletions.
72 changes: 72 additions & 0 deletions LeeSeminSU/LeeSeminSU.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
76DFF9372CD7B4F200C373C3 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 76DFF9362CD7B4F200C373C3 /* Preview Assets.xcassets */; };
76FC2B712D00ABB600F10EE1 /* GridViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B702D00ABB600F10EE1 /* GridViewExample.swift */; };
76FC2B732D00AC0000F10EE1 /* ScrollViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B722D00AC0000F10EE1 /* ScrollViewExample.swift */; };
76FC2B762D00B3C000F10EE1 /* StateExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B752D00B3C000F10EE1 /* StateExample.swift */; };
76FC2B792D00B7E300F10EE1 /* BindingExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B782D00B7E300F10EE1 /* BindingExample.swift */; };
76FC2B7B2D00BA2800F10EE1 /* ObservedObjectExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B7A2D00BA2800F10EE1 /* ObservedObjectExample.swift */; };
76FC2B7D2D00C0C700F10EE1 /* EnvironmentObjectExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B7C2D00C0C700F10EE1 /* EnvironmentObjectExample.swift */; };
76FC2B852D00C49900F10EE1 /* FirstNavigationViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B842D00C49900F10EE1 /* FirstNavigationViewExample.swift */; };
76FC2B872D00C4A100F10EE1 /* SecondNavigationViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B862D00C4A100F10EE1 /* SecondNavigationViewExample.swift */; };
76FC2B8A2D00CA4200F10EE1 /* TabViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B892D00CA4200F10EE1 /* TabViewExample.swift */; };
76FC2B8D2D00CC6600F10EE1 /* SheetModifierExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B8C2D00CC6600F10EE1 /* SheetModifierExample.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -33,6 +41,14 @@
76DFF9362CD7B4F200C373C3 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
76FC2B702D00ABB600F10EE1 /* GridViewExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridViewExample.swift; sourceTree = "<group>"; };
76FC2B722D00AC0000F10EE1 /* ScrollViewExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollViewExample.swift; sourceTree = "<group>"; };
76FC2B752D00B3C000F10EE1 /* StateExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StateExample.swift; sourceTree = "<group>"; };
76FC2B782D00B7E300F10EE1 /* BindingExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingExample.swift; sourceTree = "<group>"; };
76FC2B7A2D00BA2800F10EE1 /* ObservedObjectExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObservedObjectExample.swift; sourceTree = "<group>"; };
76FC2B7C2D00C0C700F10EE1 /* EnvironmentObjectExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnvironmentObjectExample.swift; sourceTree = "<group>"; };
76FC2B842D00C49900F10EE1 /* FirstNavigationViewExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstNavigationViewExample.swift; sourceTree = "<group>"; };
76FC2B862D00C4A100F10EE1 /* SecondNavigationViewExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondNavigationViewExample.swift; sourceTree = "<group>"; };
76FC2B892D00CA4200F10EE1 /* TabViewExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabViewExample.swift; sourceTree = "<group>"; };
76FC2B8C2D00CC6600F10EE1 /* SheetModifierExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SheetModifierExample.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -89,6 +105,7 @@
76DFF92E2CD7B4F100C373C3 /* LeeSeminSU */ = {
isa = PBXGroup;
children = (
76FC2B742D00B37D00F10EE1 /* Week4 */,
76FC2B6F2D00AB7E00F10EE1 /* Week3 */,
76FC2DD82CE06C37000B329B /* Week2 */,
76DFF92F2CD7B4F100C373C3 /* LeeSeminSUApp.swift */,
Expand Down Expand Up @@ -116,6 +133,53 @@
path = Week3;
sourceTree = "<group>";
};
76FC2B742D00B37D00F10EE1 /* Week4 */ = {
isa = PBXGroup;
children = (
76FC2B8B2D00CC4D00F10EE1 /* SheetModifier */,
76FC2B882D00CA2400F10EE1 /* TabView */,
76FC2B832D00C47B00F10EE1 /* Navigation */,
76FC2B772D00B7D000F10EE1 /* State */,
);
path = Week4;
sourceTree = "<group>";
};
76FC2B772D00B7D000F10EE1 /* State */ = {
isa = PBXGroup;
children = (
76FC2B752D00B3C000F10EE1 /* StateExample.swift */,
76FC2B782D00B7E300F10EE1 /* BindingExample.swift */,
76FC2B7A2D00BA2800F10EE1 /* ObservedObjectExample.swift */,
76FC2B7C2D00C0C700F10EE1 /* EnvironmentObjectExample.swift */,
);
path = State;
sourceTree = "<group>";
};
76FC2B832D00C47B00F10EE1 /* Navigation */ = {
isa = PBXGroup;
children = (
76FC2B842D00C49900F10EE1 /* FirstNavigationViewExample.swift */,
76FC2B862D00C4A100F10EE1 /* SecondNavigationViewExample.swift */,
);
path = Navigation;
sourceTree = "<group>";
};
76FC2B882D00CA2400F10EE1 /* TabView */ = {
isa = PBXGroup;
children = (
76FC2B892D00CA4200F10EE1 /* TabViewExample.swift */,
);
path = TabView;
sourceTree = "<group>";
};
76FC2B8B2D00CC4D00F10EE1 /* SheetModifier */ = {
isa = PBXGroup;
children = (
76FC2B8C2D00CC6600F10EE1 /* SheetModifierExample.swift */,
);
path = SheetModifier;
sourceTree = "<group>";
};
76FC2DD82CE06C37000B329B /* Week2 */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -206,13 +270,21 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
76FC2B852D00C49900F10EE1 /* FirstNavigationViewExample.swift in Sources */,
76FC2B762D00B3C000F10EE1 /* StateExample.swift in Sources */,
76FC2B732D00AC0000F10EE1 /* ScrollViewExample.swift in Sources */,
76DFF9322CD7B4F100C373C3 /* ContentView.swift in Sources */,
76FC2B7B2D00BA2800F10EE1 /* ObservedObjectExample.swift in Sources */,
76FC2B792D00B7E300F10EE1 /* BindingExample.swift in Sources */,
76DFF9302CD7B4F100C373C3 /* LeeSeminSUApp.swift in Sources */,
769FAB262CE1157A00785E3D /* SpacerPaddingExample.swift in Sources */,
76FC2B8D2D00CC6600F10EE1 /* SheetModifierExample.swift in Sources */,
76FC2B7D2D00C0C700F10EE1 /* EnvironmentObjectExample.swift in Sources */,
769FAB292CE115B700785E3D /* ModifierExample.swift in Sources */,
76FC2B872D00C4A100F10EE1 /* SecondNavigationViewExample.swift in Sources */,
76BD461B2CE10C9F00E215FE /* ComponentExample.swift in Sources */,
76FC2B712D00ABB600F10EE1 /* GridViewExample.swift in Sources */,
76FC2B8A2D00CA4200F10EE1 /* TabViewExample.swift in Sources */,
76BD46132CE103C300E215FE /* ZStackExample.swift in Sources */,
76BD46112CE103AB00E215FE /* VStackHStackExample.swift in Sources */,
);
Expand Down
12 changes: 10 additions & 2 deletions LeeSeminSU/LeeSeminSU/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ import SwiftUI

struct ContentView: View {
var body: some View {

// Week2
// VStackHStackExample()
// ZStackExampleView()
// ComponentExample()
// SpacerPaddingExample()
// ModifierExample()

// Week3
// GridViewExample()
ScrollViewExample()
// ScrollViewExample()

// Week4
// StateExample()
// BindingExample()
// ObservedObjectExample()
// FirstNavigationViewExample()
SheetModifierExample()
}
}

Expand Down
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()
}
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()
}
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()
}
34 changes: 34 additions & 0 deletions LeeSeminSU/LeeSeminSU/Week4/State/BindingExample.swift
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 LeeSeminSU/LeeSeminSU/Week4/State/EnvironmentObjectExample.swift
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()
}
Loading

0 comments on commit 360c0c5

Please sign in to comment.