簡體   English   中英

如何刪除UITabBarItem下面的空格?

[英]How to remove space below the UITabBarItem?

我已經創建了一個tabBar並在其中設置了圖像,但它在tabBarItem下面留下了太多空間。 我怎么能刪除它?

這是我的tabBar不是現在顯示

在此輸入圖像描述

我想像這樣展示它

在此輸入圖像描述

顯示Tabbar

firstVC = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
thirdVC = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
forthVC = [[ForthViewController alloc] initWithNibName:@"ForthViewController" bundle:nil];

    [[UITabBar appearance] setTintColor:[UIColor whiteColor]];

    NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:firstVC,secondVC,thirdVC,forthVC, nil];

    self.tabController = [[UITabBarController alloc] init];
    [self.tabController setViewControllers:viewControllersArray animated:NO];


    [self.window addSubview:self.tabController.view];

    //self.tabController.selectedIndex = 1;

    self.tabController.delegate = self;

    self.window.rootViewController = self.tabController;
    [self.window makeKeyAndVisible];

對於tabBar背景圖片我使用了這段代碼

UIImage* tabBarBackground = [UIImage imageNamed:@"tabbarimg1.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];

並設置img項目我已使用此代碼

//used to set the tabBarItem images
        [self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"home_tab"] withFinishedUnselectedImage:[UIImage imageNamed:@"home_tab"]];
        //Set the badge on tabBarItem
        [self.tabBarItem setBadgeValue:@"15"];

正如Vytis在答案中所說:

UIBarItem上有一個屬性(UIBarButton項繼承自此類) imageInsets

要為finishedSelectedImagefinishedUnselectedImage使用全高圖像(49px),您需要設置這些圖像插入:

tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

你必須編寫以下代碼行

 item0.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); item1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); item2.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); item2.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); 

我認為你應該在xib中使用image insect,就像 在此輸入圖像描述

對於你的要求,top應該是一些正值,而bottom應該是一些相同的負值。 如果您以編程方式添加了選項卡欄,則可以參考Wills答案

暫無
暫無

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

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