책에서 시키는 대로 네비게이션 바의 색깔(bar tint)을 스토리보드에서 바꿨는데 빌드를 해보면 적용이 안되고 그냥 배경색이 그대로 나타났다...네비게이션 바의 배경색도 설정해봤는데 얘는 상태바에 색상 적용이 안됐다...
킹짱오버플로우를 보니 iOS 13부터 네비게이션 바를 커스터마이징 하는 방식이 바뀌었다고...기존의 bar tint 는 이제 더 이상 효과가 없고, UINavigationBarAppearance 를 사용하라고 한다!
accent 나 text color 의 경우 이미 스토리보드에서 다 설정을 해서 코드에서는 딱 배경색만 설정했다. 설정 시점을 처음에는 itemsViewController 에서 했다가 그냥 SceneDelegate 으로 옮겨왔는데 UINavigationController 를 따로 선언해서 거기서 처리하는 게 나았을 것 같기도 하고...뭔가 어디가 적합한 위치인지 잘 모르겠다 흑흑...
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
print(#function)
guard let _ = (scene as? UIWindowScene) else { return }
let imageStore = ImageStore()
let itemStore = ItemStore()
let navController = window!.rootViewController as! UINavigationController
// 네비게이션 바 색상 설정
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = .secondaryBrandFillColor
navController.navigationBar.standardAppearance = appearance
navController.navigationBar.compactAppearance = appearance
navController.navigationBar.scrollEdgeAppearance = appearance
}
let itemsController = navController.topViewController as! ItemsViewController
itemsController.itemStore = itemStore
itemsController.imageStore = imageStore
}
}
extension UIColor {
static let secondaryBrandFillColor = UIColor(named: "Secondary Brand Fill Color")
}