8 iphone tabbar uitabbaritem ios
我在其中创建了一个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];
Run Code Online (Sandbox Code Playgroud)
对于tabBar背景图片我使用了这段代码
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbarimg1.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
Run Code Online (Sandbox Code Playgroud)
并设置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"];
Run Code Online (Sandbox Code Playgroud)
Man*_*wal 17
正如Vytis在答案中所说:
UIBarItem上有一个属性(UIBarButton项继承自此类)
imageInsets.要使用全高图像(49像素)
finishedSelectedImage,finishedUnselectedImage您需要设置这些图像插入:
tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
你必须编写以下代码行
Run Code Online (Sandbox Code Playgroud)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答案
| 归档时间: |
|
| 查看次数: |
3935 次 |
| 最近记录: |