隱藏NavigationBar時(shí)的一個(gè)坑(很實(shí)用)
自定義iOS7導(dǎo)航欄背景,標(biāo)題和返回按鈕文字顏色
iOS手勢(shì)返回的實(shí)現(xiàn)(自定義返回按鈕)
- 修改所在視圖及下級(jí)視圖的 tabBar 背景顏色
self.navigationController.navigationBar.barTintColor = [UIColor redColor]怕犁;
- 設(shè)置自定義標(biāo)題 Title
self.navigationController.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: UIFont(name: "Times new roman", size: 20)!]
- 修改所在視圖 除標(biāo)題外的 文字顏色
self.navigationController.navigationBar.tintColor = UIColor.whiteColor()
- 透明度 Translucent
navigationController?.navigationBar.translucent = false
// 如果設(shè)置這個(gè)屬性為 True, 同時(shí)設(shè)置了一個(gè)不透明的自定義背景圖片铸豁,導(dǎo)航欄將使用一個(gè)小于1.0的系統(tǒng)不透明度給這個(gè)圖片
// 如果在設(shè)置這個(gè)屬性為 False, 同時(shí)設(shè)置了一個(gè)透明的自定義背景圖片跳芳,導(dǎo)航欄將會(huì)用給圖片提供一個(gè)黑色不透明背景如果你使用了UIBarStyleBlack, 提供白色不透明背景如果使用了UIBarStyleDefault, 或者設(shè)置為barTintColor 如果這個(gè)值有被設(shè)置的話
- 修改下一視圖的 返回按鈕 的屬性
let backButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
self.navigationItem.backBarButtonItem = backButton
- 導(dǎo)航欄樣式 barStyle
navigationController?.navigationBar.barStyle = .Black
// 這個(gè)會(huì)導(dǎo)致navigationBar 變成黑色背景
// .Default 是白色背景黑色的字
- 修改UINavigationController杖刷,UINavigationBar背景顏色斤儿,字體顏色
- (void)setNav
{
UINavigationBar *bar = [UINavigationBar appearance];
//設(shè)置顯示的顏色
bar.barTintColor = [UIColor colorWithRed:62/255.0 green:173/255.0 blue:176/255.0 alpha:1.0];
//設(shè)置字體顏色
bar.tintColor = [UIColor whiteColor];
[bar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
//或者用這個(gè)都行
[bar setTitleTextAttributes:@{UITextAttributeTextColor : [UIColor whiteColor]}];
效果圖
隱藏底部Bar
appDetaiVC.hidesBottomBarWhenPushed = YES;
NavigationController和ViewController 都可以調(diào)用該方法
自定制返回鍵
//修改系統(tǒng)返回鍵是圖片和文字剧包,會(huì)保留側(cè)拉返回功能
UIImage *backButtonImage = [[UIImage imageNamed:@"fanhui.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
//將返回按鈕的文字position設(shè)置不在屏幕上顯示
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// 開啟
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
//代理置空,否則會(huì)閃退
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//開啟iOS7的滑動(dòng)返回效果
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
{
//只有在二級(jí)頁(yè)面生效
if ([self.navigationController.viewControllers count] == 2) {
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
}
}