๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐ŸŽ iOS

[iOS/swift] UINavigaitonBar tint color iOS 15 +

by ํ‹ด๋”” 2021. 10. 21.
728x90
๋ฐ˜์‘ํ˜•

iOS 14์˜ ๊ฒฝ์šฐ large title ์—์„œ ์ ์šฉ๋˜์—ˆ๋˜ scrollEdgeAppearance ์†์„ฑ์ด iOS15์—์„œ๋Š” ๋ชจ๋“  ๋„ค๋น„๊ฒŒ์ด์…˜์— ์ ์šฉ๋œ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค..

iOS 15์—์„œ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜์—ฌ ๋„ค๋น„๊ฒŒ์ด์…˜์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ๊ธฐ์กด์— ๋„ค๋น„๊ฒŒ์ด์…˜์„ ์‚ฌ์šฉํ•œ ํ”„๋กœ์ ํŠธ๋„ ํ•œ๋ฒˆ์”ฉ ํ™•์ธํ•ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์•„์š” ๐Ÿค”

 

scrollEdgeAppearance ๋Š” 

์Šคํฌ๋กค ๊ฐ€๋Šฅํ•œ ์ปจํ…์ธ ์˜ edge๊ฐ€ navigation bar ์˜ edge์™€ ์ •๋ ฌ๋˜๋Š” ๊ฒฝ์šฐ appearance๋ฅผ ์„ธํŒ…ํ•ด ์ค๋‹ˆ๋‹ค!

์˜ˆ๋ฅผ ๋“ค์–ด์„œ big title์˜ ๊ฒฝ์šฐ title์ด ๋„ค๋น„๊ฒŒ์ด์…˜์— ๊ทธ๋ ค์ง€๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹น

 

์ด ์†์„ฑ์˜  default ๊ฐ’์€ nil ์ด์ง€๋งŒ iOS 15 ๋ถ€ํ„ฐ๋Š” ๋ชจ๋“  ๋„ค๋น„๊ฒŒ์ด์…˜์— ์ ์šฉ๋˜๊ธฐ ๋•Œ๋ฌธ์—

์ฒ˜์Œ ํ™”๋ฉด์— ๋‚˜ํƒ€๋‚˜๋Š” ๋„ค๋น„๊ฒŒ์ด์…˜์€ ํˆฌ๋ช…ํ•˜๊ฒŒ ๊ทธ ์ดํ›„ ์Šคํฌ๋กค ์ปจํ…์ธ ๋ฅผ ์Šคํฌ๋กค ํ•˜๋ฉด ๋ฐ˜ํˆฌ๋ช… ์ƒ‰์ƒ์ด ๋‚˜ํƒ€๋‚˜๋Š” ๊ฑธ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์–ด์š”

ํˆฌ๋ช…ํ•˜๊ฑฐ๋‚˜ ์›ํ•˜๋Š” ์ƒ‰์ƒ์ด ์žˆ์œผ๋ฉด ์•„๋ž˜ ๊ฐ™์ด ์†์„ฑ์„ ์ง€์ •ํ•ด ์ค๋‹ˆ๋‹ค

appDelegate์˜ 

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool

์—์„œ ์ง€์ •ํ•ด ์ฃผ๊ฑฐ๋‚˜ UIViewController์˜ ํด๋ž˜์Šค์—์„œ 

override func viewWillAppear(_ animated: Bool)

์ง€์ •ํ•ด ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let appearance = UINavigationBarAppearance()
        appearance.configureWithOpaqueBackground()
        appearance.backgroundColor = .red
        navigationController?.navigationBar.standardAppearance = appearance
        navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance
    }

์›ํ•˜๋Š” ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์ปฌ๋Ÿฌ๋ฅผ ์ง€์ •ํ•ด ์ฃผ๋ฉด ์ฒ˜์Œ๊ณผ ์Šคํฌ๋กค ์‹œ์—๋„ ๊ฐ™์€ ์ƒ‰์ƒ์„ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค

 

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

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€