自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

去掉 iOS 導(dǎo)航欄返回按鈕文本三種方案

移動(dòng)開(kāi)發(fā) iOS
方案一:該方法會(huì)出現(xiàn)部分子控制器頁(yè)面的返回按鈕文字出現(xiàn)的bug,需要在其子控制器頁(yè)面的父控制器里再次如上設(shè)置返回按鈕才行。

 [[403792]]

本文轉(zhuǎn)載自微信公眾號(hào)「網(wǎng)羅開(kāi)發(fā)」,作者街角仰望。轉(zhuǎn)載本文請(qǐng)聯(lián)系網(wǎng)羅開(kāi)發(fā)公眾號(hào)。

方案一

  1. 自定義 UINavigationController
  2. 遵守 ``` 協(xié)議
  3. 實(shí)現(xiàn)下面方法:
  1. #pragma mark --------- UINavigationBarDelegate 
  2.  
  3. - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPushItem:(UINavigationItem *)item { 
  4.      
  5.     //設(shè)置導(dǎo)航欄返回按鈕文字 
  6.     UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStylePlain target:nil action:nil]; 
  7.     /* 
  8.     NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary]; 
  9.     textAttrs[UITextAttributeTextColor] = [UIColor whiteColor]; 
  10.     [back setTitleTextAttributes:textAttrs forState:UIControlStateNormal]; 
  11.     */ 
  12.     item.backBarButtonItem = back; 
  13.      
  14.     return YES; 

注意:該方法會(huì)出現(xiàn)部分子控制器頁(yè)面的返回按鈕文字出現(xiàn)的bug,需要在其子控制器頁(yè)面的父控制器里再次如上設(shè)置返回按鈕才行

  1. 子控制器頁(yè)面的父控制器 
  2.  
  3. #pragma mark -------- 生命周期函數(shù) 
  4.  
  5. - (void)viewDidLoad { 
  6.     [super viewDidLoad]; 
  7.     // Do any additional setup after loading the view
  8.      
  9.     self.view.backgroundColor = [UIColor whiteColor]; 
  10.      
  11.     //重新設(shè)置下級(jí)子頁(yè)面導(dǎo)航欄返回按鈕文字 
  12.     UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStylePlain target:nil action:nil]; 
  13.     self.navigationItem.backBarButtonItem = item; 
  14.  

方案二

  1. 自定義 UINavigationController
  2. 遵守 協(xié)議
  3. 實(shí)現(xiàn)下面方法:
  1. #pragma mark --------- UINavigationBarDelegate 
  2.  
  3. - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPushItem:(UINavigationItem *)item { 
  4.      
  5.     //設(shè)置導(dǎo)航欄返回按鈕文字為透明的,可能造成導(dǎo)航標(biāo)題不居中的問(wèn)題 
  6.     [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal]; 
  7.     [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateHighlighted]; 
  8.      
  9.     return YES; 

方案三(推薦)

  1. 給 UIViewController 添加類(lèi)別(這里的類(lèi)別不需要導(dǎo)入可直接使用)
  2. 然后在 load 方法里面用 Method Swzilling 方法替換交換 ViewDidAppear 方法,代碼如下:
  1. #pragma mark --------- UINavigationBarDelegate 
  2.  
  3. - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPushItem:(UINavigationItem *)item { 
  4.      
  5.     //設(shè)置導(dǎo)航欄返回按鈕文字為透明的,可能造成導(dǎo)航標(biāo)題不居中的問(wèn)題 
  6.     [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal]; 
  7.     [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateHighlighted]; 
  8.      
  9.     return YES; 

 

責(zé)任編輯:武曉燕 來(lái)源: 網(wǎng)羅開(kāi)發(fā)
相關(guān)推薦

2011-04-08 11:13:50

CISCO IOS令牌桶雙桶

2010-08-24 14:47:48

CSS居中

2017-07-03 18:24:39

MySQL數(shù)據(jù)冗余庫(kù)

2022-07-22 20:00:01

高可用路由

2022-03-22 10:24:48

Linux開(kāi)源Elasticsea

2010-09-08 15:49:21

SmartyCSS

2010-09-25 17:17:19

2010-09-30 14:40:45

2024-05-28 08:17:54

2022-07-06 07:08:58

CPythonPython返回值

2011-01-18 15:35:59

jQueryJavaScriptweb

2011-09-05 12:43:23

Sencha Touc事件

2018-07-10 08:42:45

Oracle高可用集群

2020-11-24 10:13:02

Redis集群數(shù)據(jù)庫(kù)

2022-08-19 14:24:30

forPythonpythonic

2022-12-01 08:25:03

訂單超時(shí)定時(shí)任務(wù)

2010-05-25 18:50:22

MySQL安裝

2010-09-24 19:18:22

SQL索引

2024-11-26 07:47:41

2024-08-07 08:21:05

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)