iOS開(kāi)發(fā)中經(jīng)常會(huì)遇到當(dāng)導(dǎo)航欄顏色比較深時(shí)需要將StatusBar默認(rèn)的黑色文字改成白色陨晶,iOS9之后更改分為兩步对碌。
iOS中狀態(tài)欄style分為兩種:
UIStatusBarStyleLightContent //白色文字
UIStatusBarStyleDefault //默認(rèn)黑色
1.在info.plist文件中添加屬性View controller-based status bar appearance事期,并設(shè)置為NO滥壕;
2.在APPDelegate中加入以下代碼:
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
如果不執(zhí)行第一步操作,則這一段代碼將不執(zhí)行兽泣。
執(zhí)行完兩步后狀態(tài)欄應(yīng)該就更改了绎橘,但有時(shí)會(huì)需要更改單個(gè)頁(yè)面的狀態(tài)欄顏色,需要在更改界面實(shí)現(xiàn)以下兩個(gè)方法
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}