[Swift] iOS 13에서 Navigation controller의 bar tint를 바꿔도 navigation bar 색이 변하지 않는 문제

박건희·2022년 4월 6일
0

Swift

목록 보기
7/10
post-thumbnail

Xcode 13에 들어서며 Navigation bar의 기본적인 속성이 바뀌며 여러 에러가 발생하는 것 같다.
그 중 main storyboard에서 navigation controller의 Attribute Inspector를 통해 bar tint 색상을 변경할 때 적용되지 않는다는 에러가 있다.

해결 방법은 여러가지가 있지만, 코드를 통해서 바꾸는 방법이 현업에서 가장 많이 쓰인다고 해서 아래와 같은 솔루션을 가져왔다.


Insert the following code into your initial ViewController viewDidLoad function:

		let appearance = UINavigationBarAppearance()
		appearance.configureWithTransparentBackground()
		appearance.backgroundColor = UIColor.systemBlue
		appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
		navigationItem.standardAppearance = appearance
		navigationItem.scrollEdgeAppearance = appearance

You won't see a difference in the storyboard, but once you run the app in simulator the settings will be applied.
Adapted from: https://developer.apple.com/documentation/uikit/uinavigationcontroller/customizing_your_app_s_navigation_bar

profile
CJ ENM iOS 주니어 개발자

0개의 댓글