프로그래밍/iOS

[iOS] navigation bar의 large title를 쓸 때 반투명으로 바꾸는 방법

turu 2021. 8. 25. 20:12

원인

iOS13에서 navigation bar에서 large title의 기본 모양이 반투명에서 투명으로 변경되었기 때문임.

 

해결방법

방법1. 

application(_:didFinishLaunchingWithOptions:)에 아래의 코드를 작성

let appearance = UINavigationBarAppearance()
appearance.configureWithDefaultBackground()
UINavigationBar.appearance().scrollEdgeAppearance = appearance

 

https://sarunw.com/posts/uinavigationbar-changes-in-ios13/

 

UINavigationBar changes in iOS13 | Sarunw

Apple brings a lot of appearance changes in iOS13, and the navigation bar is one of them. Cover everything you should know once you build your app against iOS13 (Xcode11).

sarunw.com

 

방법2.

해당 viewController의 viewDidLoad가 아닌 viewWillAppear같은 부분에 아래의 코드를 작성

 

let app = UINavigationBarAppearance()
app.backgroundColor = .systemGroupedBackground
self.navigationController?.navigationBar.scrollEdgeAppearance = app

https://stackoverflow.com/a/56941896/14854771

 

In iOS13 the status bar background colour is different from the navigation bar in large text mode

Pre-conditions to reproduce the problem: Xcode 11 beta + iOS 13 (latest version until Jun. 12 2019) The navigation bar is in Large text mode Specify the colour of navigation bar. The status bar w...

stackoverflow.com

 

여기서 색상을 .gray, .systemGray로 했다가 색이 아래 탭바랑 다르게 구분되어서 탭바쪽 색이랑 일치되는 색을 찾아야 했음.

찾아보니 .systemGroupedBackground 색이 앱에서 시스템적으로 약간 회색으로 통일되는? 그런 색상인 것 같았음

반응형