1. 9.0之前,改变状态栏方式
.plist 文件 设置 View controller-based status bar appearance = no; 不可以继承全局状态栏风格,并重写。
application.statusBarStyle = UIStatusBarStyleLightContent;
// Setting the statusBarStyle does nothing if your application is using the default UIViewController-based status bar system.
@property(readwrite, nonatomic) UIStatusBarStyle statusBarStyle NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]") __TVOS_PROHIBITED;
2.9.0以后,可以通过 preferredStatusBarStyle 方式修改。
一 :首先设置.plist View controller-based status bar appearance = YES;
二:设计两组改变方式:
1.(多个)涉及是UINavigationController导航,动态设置切换ViewController不同
2.(单个)仅设计到某个ViewController变换
3.上述两种情况又分切换类型:push,presentmodel等调用次序不同。
三:调用 [self setNeedsStatusBarAppearanceUpdate];
如果根导航是UINavigationController 不用在主动调用,默认调用该方法。
多个:
// Override to return a child view controller or nil. If non-nil, that view controller's status bar appearance attributes will be used. If nil, self is used. Whenever the return values from these methods change, -setNeedsUpdatedStatusBarAttributes should be called.
#if UIKIT_DEFINE_AS_PROPERTIES
@property(nonatomic,readonly,nullable)UIViewController*childViewControllerForStatusBarStyleNS_AVAILABLE_IOS(7_0)__TVOS_PROHIBITED;
@property(nonatomic,readonly,nullable)UIViewController*childViewControllerForStatusBarHiddenNS_AVAILABLE_IOS(7_0)__TVOS_PROHIBITED;
#else
- (nullableUIViewController *)childViewControllerForStatusBarStyle NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
- (nullableUIViewController *)childViewControllerForStatusBarHidden NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
#endif
1.虽然View controller-based status bar appearance = YES;但是全局状态栏样式由RootViewController样式决定。
2.重写或分类重写上面方法
- (nullableUIViewController *)childViewControllerForStatusBarStyle
- (nullableUIViewController *)childViewControllerForStatusBarHidden
业务决定某个控制器状态栏重写一个或两个方式:
- (UIStatusBarStyle)preferredStatusBarStyle
- (BOOL)prefersStatusBarHidden
单个情况:
/* The preferredContentSize is used for any container laying out a child view controller.
*/
@property(nonatomic)CGSizepreferredContentSizeNS_AVAILABLE_IOS(7_0);
// These methods control the attributes of the status bar when this view controller is shown. They can be overridden in view controller subclasses to return the desired status bar attributes.
#if UIKIT_DEFINE_AS_PROPERTIES
@property(nonatomic, readonly) UIStatusBarStyle preferredStatusBarStyle NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to UIStatusBarStyleDefault
@property(nonatomic,readonly)BOOLprefersStatusBarHiddenNS_AVAILABLE_IOS(7_0)__TVOS_PROHIBITED;// Defaults to NO
// Override to return the type of animation that should be used for status bar changes for this view controller. This currently only affects changes to prefersStatusBarHidden.
@property(nonatomic,readonly)UIStatusBarAnimationpreferredStatusBarUpdateAnimationNS_AVAILABLE_IOS(7_0)__TVOS_PROHIBITED;// Defaults to UIStatusBarAnimationFade
#else
- (UIStatusBarStyle)preferredStatusBarStyle NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;// Defaults to UIStatusBarStyleDefault
- (BOOL)prefersStatusBarHidden NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;// Defaults to NO
// Override to return the type of animation that should be used for status bar changes for this view controller. This currently only affects changes to prefersStatusBarHidden.
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;// Defaults to UIStatusBarAnimationFade
#endif
// This should be called whenever the return values for the view controller's status bar attributes have changed. If it is called from within an animation block, the changes will be animated along with the rest of the animation block.
- (void)setNeedsStatusBarAppearanceUpdateNS_AVAILABLE_IOS(7_0)__TVOS_PROHIBITED;
1.主动触发
[self setNeedsStatusBarAppearanceUpdate];
2.业务决定某个控制器状态栏重写一个或两个方式:
- (UIStatusBarStyle)preferredStatusBarStyle
- (BOOL)prefersStatusBarHidden