我创建了一个tabBar
并在其中设置了图片,但它在tabBarItem
下留下了太多空间。我该如何删除?
这是我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"];
答案 0 :(得分:17)
Vytis在their answer here中说:
UIBarItem上有一个属性(UIBarButton项继承自此 class)
imageInsets
。为
finishedSelectedImage
和使用全高图像(49像素)finishedUnselectedImage
您需要设置这些图像插入内容:
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);
答案 1 :(得分:9)
我认为你应该在xib中使用image insect,
对于您的要求top应该是一些正值,而bottom应该是一些相同的负值。如果您以编程方式添加了选项卡栏,则可以参考Wills答案