Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4주차] 정지원 실습 #58

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
563 changes: 563 additions & 0 deletions week4/week4.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions week4/week4/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
35 changes: 35 additions & 0 deletions week4/week4/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "tinted"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions week4/week4/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
71 changes: 71 additions & 0 deletions week4/week4/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// ContentView.swift
// week4
//
// Created by 정지원 on 12/8/24.
//

import SwiftUI

struct ContentView: View {
var body: some View {
NavigationView {
List {
NavigationLink("프로필 보기") {
ProfileView()
}
NavigationLink("설정") {
SettingsView()
}
}
.navigationTitle("메인 화면")
}
}
}

struct ProfileView: View {
@State private var username = "정지원"
@State private var bio = "SwiftUI 개발자"

var body: some View {
Form {
Section(header: Text("사용자 정보")) {
//@State 변수로 username과 bio에 TextField 입력값을 실시간으로 반영
TextField("이름", text: $username)
TextField("자기소개", text: $bio)
}
Section(header: Text("계정 정보")) {
Text("가입일: 2024년 12월 8일")
Text("마지막 로그인: 오늘")
}
}
.navigationTitle("프로필")
}
}

struct SettingsView: View {
@State private var isNotificationEnabled = true
@State private var isDarkMode = false
@State private var selectedLanguage = "한국어"

var body: some View {
Form {
Section(header: Text("일반")) {
Toggle("알림 설정", isOn: $isNotificationEnabled)
Toggle("다크 모드", isOn: $isDarkMode)
}
Section(header: Text("언어")) {
Picker("언어 선택", selection: $selectedLanguage) {
Text("한국어").tag("한국어")
Text("English").tag("English")
Text("日本語").tag("日本語")
}
}
}
.navigationTitle("설정")
}
}

#Preview {
ContentView()
}
70 changes: 70 additions & 0 deletions week4/week4/MainTabView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// MainTabView.swift
// week4
//
// Created by 정지원 on 12/8/24.
//
import SwiftUI

struct MainTabView: View {
var body: some View {
TabView {
NavigationView {
HomeView()
}
.tabItem {
Label("홈", systemImage: "house.fill")
}

NavigationView {
SearchView()
}
.tabItem {
Label("검색", systemImage: "magnifyingglass")
}

NavigationView {
ProfileView()
}
.tabItem {
Label("프로필", systemImage: "person.fill")
}
}
}
}

struct HomeView: View {
var body: some View {
List {
ForEach(1...10, id: \.self) { item in
Text("게시물 \(item)")
}
}
.navigationTitle("홈")
}
}

struct SearchView: View {
@State private var searchText = ""

var body: some View {
VStack {
SearchBar(text: $searchText)
List {
ForEach(filterItems, id: \.self) { item in
Text(item)
}
}
}
.navigationTitle("검색")
}

private var filterItems: [String] {
let items = ["SwiftUI", "UIKit", "Combine", "Swift"]
return searchText.isEmpty ? items : items.filter { $0.contains(searchText) }
}
}

#Preview {
MainTabView()
}
47 changes: 47 additions & 0 deletions week4/week4/MainView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// MainView.swift
// week4
//
// Created by 정지원 on 12/8/24.
//
import SwiftUI

struct MainView: View {
@State private var showingModal = false

var body: some View {
Button("메시지 작성하기") {
showingModal = true
}
.sheet(isPresented: $showingModal) {
MessageView()
}
}
}

struct MessageView: View {
@Environment(\.dismiss) var dismiss
@State private var message = ""

var body: some View {
NavigationView {
VStack {
TextField("메시지를 입력하세요", text: $message)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()

Button("저장") {
dismiss()
}
}
.navigationTitle("새 메시지")
.navigationBarItems(trailing: Button("취소") {
dismiss()
})
}
}
}

#Preview {
MainView()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
42 changes: 42 additions & 0 deletions week4/week4/SearchBar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// SearchBar.swift
// week4
//
// Created by 정지원 on 12/8/24.
//

import SwiftUI

struct SearchBar: View {
@Binding var text: String

var body: some View {
HStack {
TextField("검색어를 입력하세요", text: $text)
.padding(7)
.padding(.horizontal, 25)
.background(Color(.systemGray6))
.cornerRadius(8)
.overlay(
HStack {
Image(systemName: "magnifyingglass")
.foregroundColor(.gray)
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
.padding(.leading, 8)

if !text.isEmpty {
Button(action: {
text = ""
}) {
Image(systemName: "xmark.circle.fill")
.foregroundColor(.gray)
.padding(.trailing, 8)
}
}
}
)
.padding(.horizontal, 10)
}
.padding(.vertical, 5)
}
}
17 changes: 17 additions & 0 deletions week4/week4/week4App.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// week4App.swift
// week4
//
// Created by 정지원 on 12/8/24.
//

import SwiftUI

@main
struct week4App: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
17 changes: 17 additions & 0 deletions week4/week4Tests/week4Tests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// week4Tests.swift
// week4Tests
//
// Created by 정지원 on 12/8/24.
//

import Testing
@testable import week4

struct week4Tests {

@Test func example() async throws {
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
}

}
43 changes: 43 additions & 0 deletions week4/week4UITests/week4UITests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// week4UITests.swift
// week4UITests
//
// Created by 정지원 on 12/8/24.
//

import XCTest

final class week4UITests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.

// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false

// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

@MainActor
func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()

// Use XCTAssert and related functions to verify your tests produce the correct results.
}

@MainActor
func testLaunchPerformance() throws {
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
// This measures how long it takes to launch your application.
measure(metrics: [XCTApplicationLaunchMetric()]) {
XCUIApplication().launch()
}
}
}
}
Loading