gpt4 book ai didi

ios - TabBar 上的图像未正确显示.. 在顶部显示额外的一行 - 已更新

转载 作者:行者123 更新时间:2023-12-01 18:17:12 25 4
gpt4 key购买 nike

我添加了一个 ImageView 作为我的 TabBar(具有三个 NavigationControllers)的 subview 。当我点击 tabBarController 的任何选项卡时,imageView 上的图像会相应更改(图像显示特定选项卡已选中,而其他选项卡未选中)。

但是,图像总是在 tabBar 上显示额外的一行。看起来它越过了 tabBar 的限制。我的图像尺寸为 320x64 像素(对于非视网膜 iPhone)和 640x128 像素(对于视网膜 iPhone)。

这是我为 ImageView 和 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;
}
}

请看截图。。

enter image description here

将 barStyle 设置为黑色会给我以下结果

enter image description here

这条线已经褪色了一点,但仍然可见..

最佳答案

嘿,我尝试了一些东西,它有效

tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab_mypeople.png"]];

tabBarView.frame = CGRectMake(0, 0, 320, tabBarController.tabBar.frame.size.height);

但是,图像显示有点拉伸(stretch)..

写这个不要拉伸(stretch):这将像一个魅力..!
tabBarController.tabBar.backgroundImage = [UIImage new];
tabBarController.tabBar.shadowImage = [UIImage new];

tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab_mypeople.png"]];
tabBarView.frame = CGRectMake(0, -15, 320, 64);
[tabBarController.tabBar addSubView:tabBarView];

关于ios - TabBar 上的图像未正确显示.. 在顶部显示额外的一行 - 已更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20625889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com