느려요

진짜로

IT/Mobile

[iOS/Objective-C] iOS 15에서 Navigation Bar / Tab Bar 배경 색이 새까맣게 나오는 현상

느이 2021. 9. 28. 15:33

iOS 15가 새로 나오고 나서 XCode를 업데이트 했더니

 

스토리보드의 View controller 에 Appearance 라고 새로 생겼다.

 

Standard / Compact / Scroll Edge / Compact Scroll Edge 

 

4가지 항목이 있는데 각각의 항목마다

 

Blur style, Background Color, Shadow Color 등등을 설정할수 있는 항목이 생겼는데

 

대충 살펴보니 스크롤의 위치에 따라 Navigation Bar나 Tab Bar를 이쁘게 꾸밀수 있게 해둔거 같다.

 

 

문제는

 

이렇게 갑자기 바꾸면 기존에 tintColor로 설정해둔 배경색이 적용이 안되고 투명처리가 되어서

 

시꺼멓게 나온다는 것이다.

(망할)

 

이렇게 시꺼멓게 나오면 해결방법이 두가지 있다.

 

1. 스토리보드에서 Standard와 Scroll Edge를 클릭하고 각 Appearance에서 Background 컬러를 설정해준다.

2. 소스상에서 수정해준다.

 

필자의 경우에는 앱의 테마 컬러마다 색상을 다르게 표시해야 했기 때문에

 

1번의 방법으로는 상황에 따라 원하는 색상을 표시할 수 없었다.

 

그래서 2번처럼 소스상에서 수정했다.

if (@available(iOS 15, *)){
    UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
    [appearance configureWithDefaultBackground];
    [appearance setBackgroundColor:원하는색상];
        
    [[[self navigationController] navigationBar] setStandardAppearance:appearance];
    [[[self navigationController] navigationBar] setScrollEdgeAppearance:appearance];
}

참고 : https://developer.apple.com/forums/thread/682420

 

barTintColor not working in iOS 15 | Apple Developer Forums

In iOS 15, UIKit has extended the usage of the scrollEdgeAppearance, which by default produces a transparent background, to all navigation bars. The background is controlled by when your scroll view scrolls content behind the navigation bar. Your screensho

developer.apple.com

 

 

반응형