[英]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
。要為
finishedSelectedImage
和finishedUnselectedImage
使用全高圖像(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.