@@ -15,48 +15,74 @@ class TabBarViewModel: ObservableObject {
1515
1616// MARK: - 탭 목록
1717enum Tab : String {
18-
1918 case Home, Schedule, Meal, Settings
2019}
2120
2221// MARK: - 메인화면 탭바 뷰
2322struct TabBarView : View {
2423
2524 @ObservedObject var userSettings = UserSettings ( )
26-
2725 @ObservedObject var viewModel : TabBarViewModel
2826
2927 var body : some View {
30- TabView ( selection: $viewModel. selectedTab) {
31- HomeView ( viewModel: NoticeViewModel ( ) , userSettings: UserSettings ( ) )
32- . tabItem {
33- Image ( systemName: " megaphone.fill " )
34- Text ( " 공지 " )
35- }
36- . tag ( Tab . Home)
37-
38- ScheduleView ( viewModel: ScheduleViewModel ( ) )
39- . tabItem {
40- Image ( systemName: " calendar " )
41- Text ( " 일정 " )
42- }
43- . tag ( Tab . Schedule)
44-
45- MealView ( viewModel: MealViewModel ( ) )
46- . tabItem {
47- Image ( systemName: " fork.knife " )
48- Text ( " 식단 " )
49- }
50- . tag ( Tab . Meal)
51-
52- SettingView ( viewModel: SettingViewModel ( userSettings: UserSettings ( ) ) )
53- . tabItem {
54- Image ( systemName: " gearshape " )
55- Text ( " 설정 " )
56- }
57- . tag ( Tab . Settings)
28+ VStack {
29+ switch viewModel. selectedTab {
30+ case . Home:
31+ HomeView ( viewModel: NoticeViewModel ( ) , userSettings: userSettings)
32+ case . Schedule:
33+ ScheduleView ( viewModel: ScheduleViewModel ( ) )
34+ case . Meal:
35+ MealView ( viewModel: MealViewModel ( ) )
36+ case . Settings:
37+ SettingView ( viewModel: SettingViewModel ( userSettings: userSettings) )
38+ }
39+
40+ CustomTabView ( selectedTab: $viewModel. selectedTab)
41+ . frame ( height: 60 )
5842 }
5943 . accentColor ( Color . Blue300)
6044 }
6145}
6246
47+ // MARK: - 커스텀 탭바 뷰
48+ struct CustomTabView : View {
49+
50+ @Binding var selectedTab : Tab
51+
52+ var body : some View {
53+ HStack {
54+ TabButton ( tab: . Home, selectedTab: $selectedTab, image: " megaphone.fill " , title: " 공지 " )
55+ TabButton ( tab: . Schedule, selectedTab: $selectedTab, image: " calendar " , title: " 일정 " )
56+ TabButton ( tab: . Meal, selectedTab: $selectedTab, image: " fork.knife " , title: " 식단 " )
57+ TabButton ( tab: . Settings, selectedTab: $selectedTab, image: " gearshape " , title: " 설정 " )
58+ }
59+ . frame ( maxWidth: . infinity)
60+ . background ( Color . white)
61+ }
62+ }
63+
64+ // MARK: - 탭 버튼 뷰
65+ struct TabButton : View {
66+
67+ var tab : Tab
68+ @Binding var selectedTab : Tab
69+ var image : String
70+ var title : String
71+
72+ var body : some View {
73+ Button ( action: {
74+ selectedTab = tab
75+ } ) {
76+ VStack ( spacing: 4 ) {
77+ Image ( systemName: image)
78+ . foregroundColor ( selectedTab == tab ? . Blue300 : . Gray400)
79+
80+ Text ( title)
81+ . font ( . Medium12)
82+ . foregroundColor ( selectedTab == tab ? . Blue300 : . Gray400)
83+ . environment ( \. sizeCategory, . large)
84+ }
85+ }
86+ . frame ( maxWidth: . infinity)
87+ }
88+ }
0 commit comments