自訂iOS導覽列背景,標題和返回按鈕文字顏色

來源:互聯網
上載者:User

標籤:導航   5.0   ssh   stat   art   ora   tintcolor   style   ons   

一、導覽列的背景和文字Color:

方法一:

  1. //設定NavigationBar 背景顏色&title 顏色  
  2. [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:20/255.0 green:155/255.0 blue:213/255.0 alpha:1.0]];  
  3. [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];  

方法二:

  1. //設定NavigationBar背景顏色  
  2. [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];  
  3. //@{}代表Dictionary  
  4. [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];  

二、導覽列使用背景圖片:

1. [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];  

三、導覽列標題的字型:

UITextAttributeFont - 字型

UITextAttributeTextColor - 文字顏色

UITextAttributeTextShadowColor - 文字陰影顏色

UITextAttributeTextShadowOffset - 位移用於文本陰影

  1. NSShadow *shadow = [[NSShadow alloc] init];  
  2. shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];  
  3. shadow.shadowOffset = CGSizeMake(0, 1);  
  4. [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:  [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,  
  5. shadow, NSShadowAttributeName,  
  6. [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil nil]];  

四、圖片作為導覽列標題:

  1. self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"appcoda-logo.png"]];  

五、添加多個欄按鈕項目:

  1. UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action: nil nil];  
  2. UIBarButtonItem *cameraItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action: nil nil];  
  3. NSArray *itemsArr = @[shareItem,cameraItem];  
  4. self.navigationItem.rightBarButtonItems = itemsArr; 

六、自訂後退按鈕的文字和顏色:

方法一:

  1. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];  
  2. self.navigationItem.backBarButtonItem = item;  
  1. [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];  
  1. [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:19.0]}];  
  2.   
  3. self.title=[NSString stringWithFormat:@"第%lu頁",(unsigned long)self.navigationController.viewControllers.count];  
  4.   
  5. //自訂返回按鈕  
  6. UIImage *backButtonImage = [[UIImage imageNamed:@"fanhui.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)];  
  7. [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];  
  8. //將返回按鈕的文字position設定不在螢幕上顯示  
  9. [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];  

自訂iOS導覽列背景,標題和返回按鈕文字顏色

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.