From b4cd68ff218fa73554988a273926670c0777260c Mon Sep 17 00:00:00 2001 From: yook Date: Tue, 16 May 2023 15:55:53 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8[feat]:=20=ED=8F=B0=ED=8A=B8=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EC=B6=94=EA=B0=80,=20userdefault=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Application/TodoListApp.swift | 3 +- .../View/MainList/DynamicFilteredVIew.swift | 2 +- .../UI/View/MainList/TaskManagerView.swift | 78 ++++++++++++++----- .../TodoList/Sources/Utills/Font/Font.swift | 18 +++++ 4 files changed, 78 insertions(+), 23 deletions(-) diff --git a/TodoList/TodoList/Sources/Application/TodoListApp.swift b/TodoList/TodoList/Sources/Application/TodoListApp.swift index dacb4dd..fb61c49 100644 --- a/TodoList/TodoList/Sources/Application/TodoListApp.swift +++ b/TodoList/TodoList/Sources/Application/TodoListApp.swift @@ -12,13 +12,14 @@ import CoreData struct TodoListApp: App { let persistenceController = PersistenceController.shared @State private var showLanchView: Bool = true + @StateObject var fontSettings = FontSettings() var body: some Scene { WindowGroup { ZStack{ TodoLIstMainHomeView() .environment(\.managedObjectContext, persistenceController.container.viewContext) - + .environmentObject(fontSettings) ZStack{ if showLanchView { LanchView(showLanchView: $showLanchView) diff --git a/TodoList/TodoList/Sources/UI/View/MainList/DynamicFilteredVIew.swift b/TodoList/TodoList/Sources/UI/View/MainList/DynamicFilteredVIew.swift index 0d394c3..5e19f32 100644 --- a/TodoList/TodoList/Sources/UI/View/MainList/DynamicFilteredVIew.swift +++ b/TodoList/TodoList/Sources/UI/View/MainList/DynamicFilteredVIew.swift @@ -63,7 +63,7 @@ struct DynamicFilteredView: View where T: NSManagedObject{ Text("할일 추가 하러 가기 🥳") .font(.custom("나눔손글씨 둥근인연", size: 20)) .foregroundColor(.white) - .frame(width: geometry.size.width / 2 , height: geometry.size.width / 8) + .frame(width: geometry.size.width / 2, height: geometry.size.width / 8) .frame(maxWidth: .infinity) .background(animate ? ColorAsset.mainViewColor : ColorAsset.mainColor) .cornerRadius(12) diff --git a/TodoList/TodoList/Sources/UI/View/MainList/TaskManagerView.swift b/TodoList/TodoList/Sources/UI/View/MainList/TaskManagerView.swift index a100e30..e1cb890 100644 --- a/TodoList/TodoList/Sources/UI/View/MainList/TaskManagerView.swift +++ b/TodoList/TodoList/Sources/UI/View/MainList/TaskManagerView.swift @@ -15,10 +15,15 @@ struct TaskManagerView: View { @Environment(\.managedObjectContext) var context // MARK: Edit Button Context @Environment(\.editMode) var editButton + // MARK: Font Select + @EnvironmentObject var fontSettings: FontSettings var body: some View { - VStack { - calenderView() + NavigationView { + VStack { + calenderView() + } + } } @@ -34,7 +39,7 @@ struct TaskManagerView: View { HStack(spacing: 10){ - ForEach(taskModel.currentWeek,id: \.self){day in + ForEach(taskModel.currentWeek, id: \.self){day in VStack(spacing: 10){ Text(taskModel.extractDate(date: day, format: "dd")) @@ -54,9 +59,9 @@ struct TaskManagerView: View { .foregroundStyle(taskModel.isToday(date: day) ? .primary : .secondary) .foregroundColor(taskModel.isToday(date: day) ? .white : ColorAsset.dateColor) // MARK: Capsule Shape - .frame(width: (gemotry.size.width / 9) , height: (gemotry.size.height / 9)) + .frame(width: (gemotry.size.width / 9), height: (gemotry.size.height / 9)) .background( - + ZStack{ // MARK: Matched Geometry Effect if taskModel.isToday(date: day){ @@ -88,14 +93,14 @@ struct TaskManagerView: View { .ignoresSafeArea(.container, edges: .top) // MARK: Add Button .overlay( - + Button(action: { taskModel.addNewTask.toggle() }, label: { Image(systemName: "plus") .foregroundColor(.white) .padding() - .background(ColorAsset.mainViewColor,in: Circle()) + .background(ColorAsset.mainViewColor, in: Circle()) }) .padding() @@ -123,9 +128,9 @@ struct TaskManagerView: View { } // MARK: Task Card View @ViewBuilder - func taskCardView(task: Task)->some View{ + func taskCardView(task: Task) -> some View{ // MARK: Since CoreData Values will Give Optinal data - HStack(alignment: editButton?.wrappedValue == .active ? .center : .top,spacing: 30){ + HStack(alignment: editButton?.wrappedValue == .active ? .center : .top, spacing: 30){ // If Edit mode enabled then showing Delete Button if editButton?.wrappedValue == .active{ // Edit Button for Current and Future Tasks @@ -160,9 +165,9 @@ struct TaskManagerView: View { .fill(taskModel.isCurrentHour(date: task.taskDate ?? Date()) ? (task.isCompleted ? .green : ColorAsset.dateColor) : .clear) .frame(width: 15, height: 15) .background( - + Circle() - .stroke(ColorAsset.dateColor,lineWidth: 0.5) + .stroke(ColorAsset.dateColor, lineWidth: 0.5) .padding(-3) ) .scaleEffect(!taskModel.isCurrentHour(date: task.taskDate ?? Date()) ? 0.8 : 1) @@ -179,13 +184,16 @@ struct TaskManagerView: View { VStack(alignment: .leading, spacing: 12) { Text(task.taskTitle ?? "") - .font(.title2.bold()) - .foregroundColor(ColorAsset.dateColor) + .font(.custom(fontSettings.selectedFont.rawValue, size: 20)) + //.font(.title2.bold()) + //.foregroundColor(ColorAsset.dateColor) Text(task.taskDescription ?? "") - .font(.callout) - .foregroundColor(Color(.lightGray)) - .foregroundStyle(.secondary) + //.font(.callout) + //.foregroundColor(Color(.lightGray)) + //.foregroundStyle(.secondary) + .font(.custom(fontSettings.selectedFont.rawValue, size: 20)) + } .hLeading() @@ -208,7 +216,7 @@ struct TaskManagerView: View { Image(systemName: "checkmark") .foregroundStyle(.black) .padding(10) - .background(ColorAsset.titleColor,in: RoundedRectangle(cornerRadius: 10)) + .background(ColorAsset.titleColor, in: RoundedRectangle(cornerRadius: 10)) } } Text(task.isCompleted ? "Marked as Completed" : "Mark Task as Completed") @@ -222,7 +230,7 @@ struct TaskManagerView: View { .foregroundColor(taskModel.isCurrentHour(date: task.taskDate ?? Date()) ? ColorAsset.dateColor : ColorAsset.dateColor) .padding(taskModel.isCurrentHour(date: task.taskDate ?? Date()) ? 15 : 0) - .padding(.bottom,taskModel.isCurrentHour(date: task.taskDate ?? Date()) ? 0 : 10) + .padding(.bottom, taskModel.isCurrentHour(date: task.taskDate ?? Date()) ? 0 : 10) .hLeading() .background( Color("MainColor2") @@ -234,7 +242,7 @@ struct TaskManagerView: View { } // MARK: Header @ViewBuilder - func headerView()->some View{ + func headerView() -> some View{ HStack(spacing: 10){ VStack(alignment: .leading, spacing: 10) { Text(Date().formatted(date: .abbreviated, time: .omitted)) @@ -247,14 +255,42 @@ struct TaskManagerView: View { // MARK: Edit Button EditButton() .foregroundColor(ColorAsset.mainViewColor) + // MARK: Setting Button + NavigationLink { + settingView() + } label: { + Text("설정") + } + } .padding() - .padding(.top,getSafeArea().top) + .padding(.top, getSafeArea().top) + } + + @ViewBuilder + func settingView() -> some View { + VStack { + List(FontType.allCases, id: \.self) { font in + Button { + fontSettings.selectedFont = font + } label: { + HStack { + Text(font.rawValue) + if font == fontSettings.selectedFont { + Spacer() + Image(systemName: "checkmark") + } + } + } + } + } + .navigationTitle("본문 폰트 설정") + } } struct TaskManagerView_Previews: PreviewProvider { static var previews: some View { - TaskManagerView() + TaskManagerView() } } diff --git a/TodoList/TodoList/Sources/Utills/Font/Font.swift b/TodoList/TodoList/Sources/Utills/Font/Font.swift index 14a33a0..2dd8d86 100644 --- a/TodoList/TodoList/Sources/Utills/Font/Font.swift +++ b/TodoList/TodoList/Sources/Utills/Font/Font.swift @@ -11,3 +11,21 @@ struct Fonts { static let mainFont: String = "나눔손글씨 둥근인연" static let subFont: String = "나눔손글씨 맛있는체" } + +enum FontType: String, CaseIterable { + case mainFont = "나눔손글씨 둥근인연" + case subFont = "나눔손글씨 맛있는체" +} + +class FontSettings: ObservableObject { + @Published var selectedFont: FontType { + didSet { + UserDefaults.standard.set(selectedFont.rawValue, forKey: "SelectedFont") + } + } + + init() { + let savedFont = UserDefaults.standard.string(forKey: "SelectedFont") ?? FontType.mainFont.rawValue + selectedFont = FontType(rawValue: savedFont) ?? .mainFont + } +}