剛剛建項(xiàng)目的時候遇到的,記錄一下技扼。
首先:
將info.plist
中的View controller-based status bar appearance
設(shè)置為NO
伍玖。
如果沒有的話,就添加一條設(shè)置為NO
剿吻。
沒有設(shè)置的話窍箍,我剛試過,怎么改變status bar
都沒有效果。
然后:
1椰棘、就可以按照UI效果做相應(yīng)調(diào)整了纺棺。
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
UIStatusBarStyleDefault // 黑色
UIStatusBarStyleLightContent // 白色
// 目前來說基本就這兩個,還有兩個是7.0之前的
可以放在AppDelegate中,也可以放在BaseViewController中邪狞,看實(shí)際需求.
2祷蝌、也可以在viewController中重寫這個方法同樣的效果
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}
3、也可以在General中設(shè)置
4帆卓、或者如果只有一個頁面有特殊要求的話巨朦,可以這樣
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
}
5、如果沒有導(dǎo)航條的頁面鳞疲,會感覺到狀態(tài)欄是不透明的罪郊,下面的顏色頂不到最上面,像這樣:
請相信狀態(tài)欄其實(shí)是透明的尚洽,是因?yàn)楦叨鹊拈_始坐標(biāo)是從狀態(tài)欄下開始的悔橄,所以減去狀態(tài)欄的高度就好了
// 高度設(shè)成-20 就好了
self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, -20, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
6、隱藏方法腺毫,同樣也要View controller-based status bar appearance
設(shè)置為NO
[UIApplication sharedApplication].statusBarHidden = YES;
// 同樣有重寫方法
- (BOOL)prefersStatusBarHidden{
return YES;
}
最后
Hide status bar
勾選之后 plist中會出現(xiàn):
網(wǎng)上說這個屬性設(shè)置為YES會使啟動頁的狀態(tài)欄隱藏掉癣疟。
但是我試了一下:
當(dāng)View controller-based status bar appearance
設(shè)置為YES
時,是隱藏掉啟動頁的狀態(tài)欄潮酒。
當(dāng)View controller-based status bar appearance
設(shè)置為NO
時睛挚,所有的狀態(tài)欄都隱藏掉了。