[iOS] navigationBar 의 색상이StatusBar 까지 적용되지 않을때

chaentopia·2022년 11월 25일
0
post-thumbnail

첫번째 글을 이런 걸로 작성하게 될 줄은 몰랐는데... 까먹기 전에 아카이빙 한다는 마음으로 작성해봅니다.. 나중에 정제된 글로 수정 예정............

잘못된 것이 있다면 꼭 알려주세요..

함수로 네비게이션바를 세팅을 했는데

private func setNavigationBar() {
        let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 36))
        let topTitle = UILabel(frame: CGRect(x: 0, y: 0, width: 199, height: 29))
        

        topTitle.numberOfLines = 1
        topTitle.textAlignment = .center
        topTitle.font = .systemFont(ofSize: 24, weight: .semibold)
        topTitle.textColor = .white
        topTitle.text = "title"
        
        self.navigationItem.titleView = containerView
        self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
        self.navigationController?.navigationBar.shadowImage = UIImage()
        self.navigationController?.navigationBar.backgroundColor = .systemCyan
        self.navigationController?.navigationBar.isTranslucent = false
 }

이렇게 작성하면..

statusBar 부분까지 background 색상이 적용이 안되어서 막 safearea를 무시하는 방법도 찾아보고.. statusbar도 찾아보고 했는데

iOS 13에서 뭐가 바뀌어서.. 다르게 써야 한다는 이야기를 봄

그래서

let appearance = UINavigationBarAppearance()
        appearance.configureWithOpaqueBackground()
        appearance.backgroundColor = .systemCyan
        self.navigationController?.navigationBar.standardAppearance = appearance
        self.navigationController?.navigationBar.scrollEdgeAppearance = self.navigationController?.navigationBar.standardAppearance

func 안에 이렇게 넣어줬더니

잘되네요
근데 제가 해야 하는 일은 statusBar부터 navigationBar까지 그라데이션으로 다 연결 되어야 하는 건데 지금 형태는 연결이 된 게 아니라 그냥 색상만 맞춘 것이라..
이건 더 찾아봐야 할 것 같습니다... ㅜㅜ

아니면 냅다 전체에 다 이미지를 넣는 방법은 없는지.. 찾아보겠습니다...............

profile
the pale blue dot

0개의 댓글