diff --git a/Handy/Handy-Storybook/Component/NavigationViewController.swift b/Handy/Handy-Storybook/Component/NavigationViewController.swift index bc7577d..41d1e11 100644 --- a/Handy/Handy-Storybook/Component/NavigationViewController.swift +++ b/Handy/Handy-Storybook/Component/NavigationViewController.swift @@ -10,16 +10,17 @@ import Handy import SnapKit class NavigationViewController: HandyNavigation { + let page1: UIViewController = { let viewController = UIViewController() - viewController.view.backgroundColor = HandySemantic.bgBasicStrong + viewController.view.backgroundColor = HandySemantic.bgStatusPositive viewController.tabBarItem = UITabBarItem(title: "Label", image: HandyIcon.icHomeFilled, selectedImage: HandyIcon.icHomeFilled) return viewController }() let page2: UIViewController = { let viewController = UIViewController() - viewController.view.backgroundColor = HandySemantic.bgStatusPositive + viewController.view.backgroundColor = HandySemantic.bgBasicBlack viewController.tabBarItem = UITabBarItem(title: "Label", image: HandyIcon.icHomeFilled, selectedImage: HandyIcon.icHomeFilled) return viewController }() @@ -40,22 +41,13 @@ class NavigationViewController: HandyNavigation { let page5: UIViewController = { let viewController = UIViewController() - viewController.view.backgroundColor = HandySemantic.bgBasicLight + viewController.view.backgroundColor = HandySemantic.iconBasicSecondary viewController.tabBarItem = UITabBarItem(title: "Label", image: HandyIcon.icHomeFilled, selectedImage: HandyIcon.icHomeFilled) return viewController }() - override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { - super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) - - self.setViewControllers([page1, page2, page3, page4, page5], animated: true) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - override func viewDidLoad() { super.viewDidLoad() + setViewControllers([page1, page2, page3, page4, page5], animated: false) } } diff --git a/Handy/Handy/Source/Component/HandyNavigation.swift b/Handy/Handy/Source/Component/HandyNavigation.swift index 8696df4..c4bb90b 100644 --- a/Handy/Handy/Source/Component/HandyNavigation.swift +++ b/Handy/Handy/Source/Component/HandyNavigation.swift @@ -15,6 +15,8 @@ open class HandyNavigation: UITabBarController { /// 상단 탭바에 사용되는 디바이더입니다. let divider = HandyDivider() + private let customTabBar = CustomTabBar() + open override func viewDidLoad() { super.viewDidLoad() setupView() @@ -22,6 +24,7 @@ open class HandyNavigation: UITabBarController { /// 뷰 세팅 private func setupView() { + setValue(customTabBar, forKey: "tabBar") setProperties() setLayouts() } @@ -81,13 +84,8 @@ extension HandyNavigation { viewControllers?.forEach { if $0.tabBarItem.title == nil { // title이 없는 경우 - $0.tabBarItem.imageInsets = UIEdgeInsets(top: itemImageVerticalInset, - left: 0, - bottom: -itemImageVerticalInset, - right: 0) + $0.tabBarItem.imageInsets = UIEdgeInsets(top: itemImageVerticalInset, left: 0, bottom: -itemImageVerticalInset, right: 0) } else { - // FIXME: 레이아웃 적용 안됨 - // title이 있는 경우: 이미지와 텍스트 위치 조정 tabBarItem.imageInsets = UIEdgeInsets( top: itemImageVerticalInset, left: 0, @@ -99,16 +97,24 @@ extension HandyNavigation { } } -/** - TODO: 레이아웃 간격 - - UITabBar의 높이 설정 불가 - - UITabBar의 아이콘 크기 설정 불가 - */ +//MARK: - 네비게이션 바 레이아웃 설정 (Safe Area 처리) +class CustomTabBar: UITabBar { + let fixedHeight: CGFloat = 56 -/** - 파일 변경점 - 1. Component폴더 생성 - 2. HandyNavigation.swift 생성 - 3. HandyIcon.swift 파일에 icHomeFilled 추가 - 4. Asset/HandyIcon에 이미지 추가 - */ + override func layoutSubviews() { + super.layoutSubviews() + + // Safe Area를 고려한 높이 설정 + var newFrame = self.frame + let safeAreaInsets: CGFloat = { + if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, + let window = windowScene.windows.first { + return window.safeAreaInsets.bottom + } + return 0 + }() + newFrame.size.height = fixedHeight + safeAreaInsets + newFrame.origin.y = UIScreen.main.bounds.height - newFrame.size.height + self.frame = newFrame + } +}