設(shè)置導(dǎo)航欄標(biāo)題
self.navigationItem.title = @"導(dǎo)航欄標(biāo)題"
設(shè)置導(dǎo)航欄的背景顏色
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
設(shè)置導(dǎo)航欄的背景圖片
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"圖片"] forBarMetrics:UIBarMetricsDefault];
UIBarMetrics枚舉:
UIBarMetricsDefault -> 在橫豎屏都顯示
UIBarMetricsCompact -> 只有橫屏才顯示
...
更改頂部狀態(tài)欄的顏色
系統(tǒng)提供兩種樣式:
- UIStatusBarStyleDefault:系統(tǒng)默認(rèn)樣式,黑色內(nèi)容悔橄,用于淺色的背景
- UIStatusBarStyleLightContent:白色內(nèi)容耙替,用于深色的背景
- 需要在工程的Info.plist文件中添加一行View controller-based status bar appearance,設(shè)置為NO
- 然后在ViewController中添加如下方法
- (UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
設(shè)置返回按鈕
- 設(shè)置返回按鈕的顏色
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
- 設(shè)置返回按鈕圖片
// imageWithRenderingModel:方法搓扯,參數(shù)UIImageRenderingModeAlwaysOriginal表示總是用原圖渲染,如果不這么設(shè)置探赫,返回的按鈕將會顯示tintColor的顏色厦画,UITabbarItem存在同樣問題
UIImage *image = [[UIImage imageName:@""] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithImage:style:UIBarButtonItemStyleBordered target:self action:@selector(backMethod)];
self.navigationItem.leftBarButtonItem = leftButton;
// 修復(fù)navigationController側(cè)滑關(guān)閉失效問題
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
- 設(shè)置返回按鈕文字
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(backMethod)];
letfButton.tintColor = [UIColor whiteColor];
self.navigationItem.leftBarButtonItem = leftButton;
- 自定義返回按鈕
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButtonView];
self.navigationItem.leftBarButtonItem = leftBarButton;
rightBarButton 參照如上
隱藏導(dǎo)航欄底部的線條
- 設(shè)置導(dǎo)航欄的shadowImage
UINavigationBar *navigationBar = self.navigationController.navigationBar;
[navigationBar setShadowImage:[UIImage new]]
- 設(shè)置導(dǎo)航欄的clipsToBounds的值
self.navigationController.navigationbar.clipsToBounds = YES;
設(shè)置導(dǎo)航欄添加多個按鈕
- 方法一
UIBarButtonItem *closeItem = [[UIBarButtonItem alloc] initWithTitle:@"關(guān)閉" style:UIBarButtonItemStylePlain target:self action:@selector(close)];
self.navigationItem.leftItemSupplementBackButton = YES;
- 方法二
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeSystem];
...自定義button過程
UIBarButton *backItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
self.navigationItem.leftBarButtonItems = @[backItem, closeItem];
導(dǎo)航欄全局屬性設(shè)置
[UINavigationBar appearance].barStyle = UIBarStyleBlack;
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];