Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Observable
- combine
- swift documentation
- scrollview
- MVVM
- UITextView
- ribs
- collectionview
- Clean Code
- 애니메이션
- Protocol
- tableView
- 스위프트
- uitableview
- 리펙토링
- HIG
- ios
- Refactoring
- SWIFT
- swiftUI
- clean architecture
- 클린 코드
- map
- rxswift
- Human interface guide
- 리팩토링
- RxCocoa
- Xcode
- uiscrollview
- UICollectionView
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - swift] 전역적으로 TabBar, NavigationBar 색상 변경 방법 (AppAppearance, appearance) 본문
iOS 응용 (swift)
[iOS - swift] 전역적으로 TabBar, NavigationBar 색상 변경 방법 (AppAppearance, appearance)
jake-kim 2021. 10. 13. 03:30apperance() 메소드
- 네비게이션: UINavigationBar.appearance()
- 탭바: UITabBar.appearance()
AppDelegate에서 전역적으로 세팅
- AppAppearance.setupAppearance()으로 접근
final class AppAppearance {
static func setupAppearance() {
...
}
}
UINavigationBar.appearance()
- 배경: UINavigationBar.appearance().backgroundColor = UIColor.darkGray
- 타이틀 색상: UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.orange]

- 아이템 색상: UINavigationBar.appearance().tintColor = .lightGray

TabBar.appearance()
- 배경 색상: UITabBar.appearance().backgroundColor = .gray
- 버튼 색상: UITabBar.appearance().tintColor = .black
- 선택 item과 미선택 item의 색상은 os에서 자동으로 처리

전체 코드
- 정의
final class AppAppearance {
static func setupAppearance() {
// MARK: - NavigationBar
/// navigationBar 배경 색상
UINavigationBar.appearance().backgroundColor = UIColor.darkGray
/// navigationBar의 버튼 색상 (ex - back 버튼)
UINavigationBar.appearance().tintColor = .lightGray
/// navigationBar 중앙에 존재하는 title 색상
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.orange]
// MARK: - TabBar
/// TabBar의 버튼 색상 (ex - 탭바 위에 있는 검색 이미지의 색상)
/// 단, 현재 선택된 ViewController의 tab의 색상과 선택되어 있지 않은 tab의 색상은 자동으로 조정
UITabBar.appearance().tintColor = .black
/// TabBar의 background 색상
UITabBar.appearance().backgroundColor = .gray
}
}
- 호출하는 곳: AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AppAppearance.setupAppearance() // <-
return true
}