iOS에 시스템 설정에 따라 다크모드를 적용하려면,
AppDelegate.swift
의 didFinishLaunchingWithOptions
메서드에 아래 내용을 추가한다.
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 13.0, *) {
window?.overrideUserInterfaceStyle = .unspecified
}
return true
}
}
왜 didFinishLaunchingWithOptions
일까?
앱 Launch 시점에 UI 전체 설정을 적용하기 때문이다.