簡體   English   中英

UITabBarController背景圖像設置不正確

[英]UITabBarController background image is not set correctly

我正在嘗試以編程方式添加UITabBarController 一切正常,但我遇到兩個問題。

  1. 我正在設置標簽欄背景圖像,但它顯示的是我什至沒有的其他圖像。 我正在使用此圖像作為上面帶有綠線的標簽欄背景圖像:

但它在底部顯示了另一條綠線,如下所示:

在此處輸入圖片說明

這是我為此使用的代碼:

[self.myTabBarController.tabBar setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tabbar.png" ofType:nil]]];
  1. 另一個問題是,我正在使用以下代碼設置標簽欄項圖像:

      MyViewController *myController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil]; UINavigationController *myNavController = [[UINavigationController alloc] initWithRootViewController: myController]; [myNavController.tabBarItem initWithTitle:@"" image:[UIImage imageNamed:@"ads_inactive.png"] selectedImage:[UIImage imageNamed:@"ads_active.png"]]; 

設置了圖像,但是當我嘗試使用以下方法在MyViewControllerviewDidLoad添加標題時:

self.title = @"My Ads";

它也在標簽欄項上顯示相同的標題,但我不希望在其中顯示任何標題。

如何解決此問題? 謝謝

圖像尺寸小於標簽欄的框架尺寸,因此要覆蓋到框架區域,背景圖像將顯示兩次。 您可以通過兩種方式對其進行更改:1.)更改不是最佳選擇的圖像大小; 2.)設置tabBar的內容插圖,例如(0,0,0,0)

例:

UITabBar *tabBar = self.tabBarController.tabBar;
iterm0.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

UITabBarItem *iterm0 = [tabBar.items objectAtIndex:0];
[iterm0 setImage:[[UIImage imageNamed:@"tab1_normal"]
                  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[iterm0 setSelectedImage:[[UIImage imageNamed:@"tab1_selected"]
                          [(UITabBarItem *)[self.tabBarController.tabBar.items objectAtIndex:0] setTitle:@""];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM