UINavigationController

隱藏NavigationBar時的一個坑(很實用)
自定義iOS7導航欄背景,標題和返回按鈕文字顏色
iOS手勢返回的實現(自定義返回按鈕)

  • 修改所在視圖及下級視圖的 tabBar 背景顏色
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
  • 設置自定義標題 Title
self.navigationController.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: UIFont(name: "Times new roman", size: 20)!]
  • 修改所在視圖 除標題外的 文字顏色
 self.navigationController.navigationBar.tintColor = UIColor.whiteColor()
  • 透明度 Translucent
 navigationController?.navigationBar.translucent = false 
// 如果設置這個屬性為 True, 同時設置了一個不透明的自定義背景圖片,導航欄將使用一個小于1.0的系統(tǒng)不透明度給這個圖片
// 如果在設置這個屬性為 False, 同時設置了一個透明的自定義背景圖片,導航欄將會用給圖片提供一個黑色不透明背景如果你使用了UIBarStyleBlack, 提供白色不透明背景如果使用了UIBarStyleDefault, 或者設置為barTintColor 如果這個值有被設置的話
  • 修改下一視圖的 返回按鈕 的屬性
let backButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
  self.navigationItem.backBarButtonItem = backButton
  • 導航欄樣式 barStyle
 navigationController?.navigationBar.barStyle = .Black
    // 這個會導致navigationBar 變成黑色背景 
    // .Default 是白色背景黑色的字
  • 修改UINavigationController,UINavigationBar背景顏色,字體顏色
- (void)setNav
{
    UINavigationBar *bar = [UINavigationBar appearance];

    //設置顯示的顏色
    bar.barTintColor = [UIColor colorWithRed:62/255.0 green:173/255.0 blue:176/255.0 alpha:1.0];

    //設置字體顏色
    bar.tintColor = [UIColor whiteColor];

    [bar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];

//或者用這個都行
    [bar setTitleTextAttributes:@{UITextAttributeTextColor : [UIColor whiteColor]}];
效果圖

隱藏底部Bar

appDetaiVC.hidesBottomBarWhenPushed = YES;
NavigationController和ViewController 都可以調用該方法
自定制返回鍵

 //修改系統(tǒng)返回鍵是圖片和文字,會保留側拉返回功能
  UIImage *backButtonImage = [[UIImage imageNamed:@"fanhui.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
  [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
  //將返回按鈕的文字position設置不在屏幕上顯示
  [[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]; 
//代理置空,否則會閃退
  if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
 self.navigationController.interactivePopGestureRecognizer.delegate = nil;
    }
  }
- (void)viewDidAppear:(BOOL)animated {
   [super viewDidAppear:animated];
   //開啟iOS7的滑動返回效果
  if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) 
  { 
   //只有在二級頁面生效 
   if ([self.navigationController.viewControllers count] == 2) { 
self.navigationController.interactivePopGestureRecognizer.delegate = self; 
  }
 }
}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容