The correct way to set a light status bar text color in iOS 7 based on different ViewControllers

后端 未结 8 1251
死守一世寂寞
死守一世寂寞 2020-12-25 14:52

I need to let a specific ViewController embedded in an UINavigationController to have light status bar text color (but other ViewControllers to beh

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-25 15:17

    iOS 13 Solution(s)

    Regarding your attempt #3 - DEPRECATED

    UIApplication.setStatusBarStyle(_:animated:) has been deprecated since iOS 9. According to Apple,

    In iOS 7 and later, status bar behavior is determined by view controllers, and so calling this method has no effect by default. When view controller-based status bar appearance is disabled, this method behaves normally. To opt out of the view controller-based status bar appearance behavior, you must add the UIViewControllerBasedStatusBarAppearance key with a value of false to your app’s Info.plist file, but doing so is not recommended.

    Regarding your attempt #2 - LEGACY

    Setting the barStyle property is now (iOS 13+) considered a "legacy customization." According to Apple,

    In iOS 13 and later, customize your navigation bar using the standardAppearance, compactAppearance, and scrollEdgeAppearance properties. You may continue to use these legacy accessors to customize your navigation bar's appearance directly, but you must update the appearance for different bar configurations yourself.

    Regarding your attempt #1 - You were on the right track!

    UINavigationController is a subclass of UIViewController (who knew

提交回复
热议问题