【发布时间】:2013-12-17 04:24:28
【问题描述】:
我添加了一个 ImageView 作为我的 TabBar(具有三个 NavigationControllers)的子视图。当我点击 tabBarController 的任何选项卡时,imageView 上的图像会相应更改(图像显示该特定选项卡已选中,而其他选项卡未选中)。
但是,图像总是在 tabBar 上显示额外的一行。看起来它越过了 tabBar 的限制。我的图像尺寸为 320x64 像素(对于非视网膜 iPhone)和 640x128 像素(对于视网膜 iPhone)。
这是我为图像视图和 tabBarController 声明实例 var 的方式。
@interface HomePageViewController ()<UITabBarControllerDelegate>
{
UIImageView* tabBarView;
UITabBarController *tabBarController;
}
-(UITabBarController *) configureTheTabBarControllerWithNavControllerAtIndex:(NSInteger)index
{
UINavigationController *customerCareNavController;
UINavigationController *accAndContactsNavController;
UINavigationController *purchaseOrderNavController;
CustomerCareViewController *custCareVC;
PurchaeOrderViewController *POController;
AccountsAndContactsViewController *accAndContactsController;
custCareVC = [[CustomerCareViewController alloc] initWithNibName:@"CustomerCareViewController_iPhone" bundle:NULL];
POController = [[PurchaeOrderViewController alloc] initWithNibName:@"PurchaeOrderViewController_iPhone" bundle:NULL];
accAndContactsController = [[AccountsAndContactsViewController alloc] initWithNibName:@"AccountsAndContactsViewController_iPhone" bundle:NULL];
customerCareNavController = [[UINavigationController alloc] initWithRootViewController:custCareVC];
purchaseOrderNavController = [[UINavigationController alloc] initWithRootViewController:POController];
accAndContactsNavController = [[UINavigationController alloc] initWithRootViewController:accAndContactsController];
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:customerCareNavController,accAndContactsNavController,purchaseOrderNavController, nil];
switch (index) {
case 0:
tabBarController.selectedIndex = 0;
break;
case 1:
tabBarController.selectedIndex = 1;
break;
case 2:
tabBarController.selectedIndex = 2;
break;
}
tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab_mypeople.png"]];
tabBarView.frame = CGRectMake(0, -15, 320, 64);
[tabBarController.tabBar addSubview:tabBarView];
tabBarController.delegate = self;
[self selectTabBarIndex:index];
[self presentViewController:tabBarController animated:YES completion:NULL];
return tabBarController;
}
-(void)tabBarController:(UITabBarController *)TBController didSelectViewController:(UIViewController *)viewController
{
NSUInteger indexSelected = [[TBController viewControllers] indexOfObject:viewController];
[self selectTabBarIndex:indexSelected];
}
- (void) selectTabBarIndex:(NSInteger)index
{
switch (index)
{
case 0:
tabBarView.image=[UIImage imageNamed:@"tab_myCalendar.png"];
break;
case 1:
tabBarView.image=[UIImage imageNamed:@"tab_myDetails.png"];
break;
case 2:
tabBarView.image=[UIImage imageNamed:@"TabBarItem_PO.png"];
break;
}
}
请看截图..
将 barStyle 设置为黑色会给我以下结果
线条已经淡了一点,但仍然可见..
【问题讨论】:
标签: ios iphone uitabbarcontroller