1.statusBar的style默認狀態下,電池信號之類的為黑色,背景為當前控制器的view的背景顏色。
UIStatusBarStyleLightContent, 狀態欄內容為白色。
UIStatusBarStyleDefault,狀態欄內容為黑色。
2.控制statusBar顯示的風格,如果在NavigationController統一設置風格,那么就在NavigationController中寫此方法。
- (UIStatusBarStyle)preferredStatusBarStyle{returnUIStatusBarStyleLightContent;}
3.如果要在有navigationController導航的情況下,要在viewController中拿到并修改statusBar的顏色的話
UIView*statusBar = [[[UIApplicationsharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];NSLog(@"statusBar.backgroundColor--->%@",statusBar.backgroundColor);if([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {? ? ? ? statusBar.backgroundColor = color;? ? }
4.設置 navigationBar 導航條leftItem和rightItem字體顏色,和導航條顏色
//navigationItem字體的顏色[self.navigationController.navigationBar setTintColor:[UIColorblackColor]];//導航欄顏色[self.navigationController.navigationBar setBarTintColor:[UIColorwhiteColor]];
5.設置navigationItem
UIBarButtonItem*item = [[UIBarButtonItemalloc] initWithTitle:@""style:UIBarButtonItemStyleDonetarget:nilaction:nil];self.navigationItem.backBarButtonItem = item;
6.在controller中設置 statusBar 和navigationBar 透明
[[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:1];
self.view.backgroundColor = [UIColor ClearnColor];通常情況給self.view的背景色設置成圖片,將導航條設為透明,就完成整個狀態欄和導航條的透明了。
7.設置導航條標題的顏色 (AttributeString)
self.navigationController.navigationBar.titleTextAttributes = @{UITextAttributeTextColor: [UIColor whiteColor]};