Conversation
|
|
||
| /// 뷰 세팅 | ||
| private func setupView() { | ||
| setValue(customTabBar, forKey: "tabBar") |
There was a problem hiding this comment.
tabBar의 appearance를 바꾸지 않고 UITabBarController의 tabBar 요소를 직접 갈아끼우는 방식을 사용하신 이유가 궁금합니다!
단순 사이즈만 조정하고 싶으신거라면, UITabBar의 사이즈를 조절하는 함수를 override 하는 방식으로도 가능할 것 같아서요! (아마 sizeThatFits일꺼에요)
There was a problem hiding this comment.
굳이 UITabBarController의 tabBar를 customTabBar로 갈아끼워서 높이를 조절할 필요는 없다고 생각하여 UITabBarControllerdml tabBar의 높이를 조절하는 것으로 코드를 수정했습니다!
| tabBarItemAppearance.normal.iconColor = HandySemantic.iconBasicDisabled // 아이콘 색상 | ||
| tabBarItemAppearance.normal.titleTextAttributes = [ | ||
| .foregroundColor: HandySemantic.textBasicDisabled, // 텍스트 색상 | ||
| .font: UIFont.systemFont(ofSize: 11)] // 텍스트 폰트 사이즈 |
There was a problem hiding this comment.
미리 선언된 타이포그래피를 재사용하는 것이 좋아보여요!
There was a problem hiding this comment.
HandyFont를 사용하여 코드 수정했습니다!
| /// title이 nil이라면 imageInsets을 조정해서 image를 중앙 정렬합니다. | ||
| public func setTabBarItemImageInsets() { | ||
| viewControllers?.forEach { | ||
| if $0.tabBarItem.title == nil { | ||
| // title이 없는 경우 | ||
| $0.tabBarItem.imageInsets = UIEdgeInsets(top: itemImageVerticalInset, left: 0, bottom: -itemImageVerticalInset, right: 0) | ||
| } else { | ||
| tabBarItem.imageInsets = UIEdgeInsets( | ||
| top: itemImageVerticalInset, | ||
| left: 0, | ||
| bottom: 0, | ||
| right: 0 | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
특정 title만 nil이고 나머지는 아닌 경우는 엄청 드물 것 같아요!
또한, title도 nil일 수 있지만 icon도 nil일 경우도 배제하면 안될 것 같구요!
저는 HandyNavigation에 이를 조절할 수 있는 프로퍼티가 있다면 좋을 것 같아요! tabBar의 title을 설정할 때도 navigation title로 설정할 수도 있기 때문에 정말 이미지를 가운데에 놓고 싶다면 이를 결정하는 프로퍼티가 따로 있는 편이 더 편할 것 같아요.
There was a problem hiding this comment.
centerItem 프로퍼티를 생성하여 HandyNavigation 생성시 centerItem = true로 설정했을 때만 모든 tabBarItem의 title을 nil로 바꾸고 아이콘을 중앙에 배치하는 것으로 수정했습니다!
override func viewDidLoad() {
super.viewDidLoad()
centerItem = false
setViewControllers([page1, page2, page3, page4, page5], animated: false)
}centerItem은 기본적으로 false입니다.
📌 Summary
HandyNavigation을 만들었습니다.
✍️ Description
💡 PR Point
CustomTabBar클래스를 정의했습니다.TabBarItem의title이nil이라면 아이콘 높이를 중앙에 배치되도록 했습니다.📚 Reference
🔥 Test
HandyNavigation.mov
title이 없을 떄 아이콘을 가운데에 배치합니다.