導(dǎo)航欄
- 隱藏與顯示
//顯示導(dǎo)航欄(兩種都可纷纫,要互相對應(yīng))
self.navigationController.navigationBar.hidden = NO;
self.navigationController.navigationBarHidden = NO;
//隱藏導(dǎo)航欄
self.navigationController.navigationBar.hidden = YES;
self.navigationController.navigationBarHidden = YES;
- 透明度
//YES為透明 NO為不透明
[self.navigationController.navigationBar setTranslucent:NO];
- 背景
//設(shè)置背景顏色
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
//設(shè)置背景圖片
[self.navigationController.navigationBar setBackgroundImage:
[UIImage imageNamed:@"nv_background.png"] forBarMetrics:UIBarMetricsDefault];
- 標(biāo)題和左右按鈕
//設(shè)置標(biāo)題顏色大小
[[UINavigationBar appearance] setTitleTextAttributes:@{ UITextAttributeTextColor :[UIColor whiteColor],UITextAttributeFont : [UIFont boldSystemFontOfSize:18]}];
//設(shè)置導(dǎo)航欄左右按鈕顏色大小
[[UIBarButtonItem appearance] setTitleTextAttributes:@{
UITextAttributeTextColor :[UIColor whiteColor],
UITextAttributeFont : [UIFont systemFontOfSize:14]
} forState:UIControlStateNormal];
- 導(dǎo)航欄下方黑線
UINavigationBar *navigationBar = self.navigationController.navigationBar;
//隱藏黑色線條
[navigationBar setShadowImage:[UIImage new]];
//修改線條顏色
[navigationBar setShadowImage:[self imageWithColor:[UIColor redColor] andSize:CGSizeMake([UIScreen mainScreen].bounds.size.width, 1)]];
//顏色生成圖片方法
- (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size
{
CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
狀態(tài)欄
在plist文件中添加如下鍵值對Status bar is initially hidden(NO為顯示狀態(tài)欄此疹,YES為隱藏“)逸吵,View controller-based status bar appearance狀態(tài)欄設(shè)置.png
- 顯示與隱藏
//顯示
[UIApplication sharedApplication].statusBarHidden = NO;
//隱藏
[UIApplication sharedApplication].statusBarHidden = YES;
- 顏色修改
//狀態(tài)欄字體顏色為黑色
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
//狀態(tài)欄字體顏色為白色
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];