我想创建一个只有 3 个按钮的自定义标签栏设计。尝试拆分图像以适合 iPhone 屏幕时出现问题。宽度为 320 时,您需要 2 个选项卡的宽度为 106,第 3 个选项卡的宽度为 108。当我以正确的尺寸创建图像时,它们不适合,我最终在右侧下方有一条 1px 的线,例如这个:
这是我正在使用的代码:
UIImage *selectedImage0 = [UIImage imageNamed:@"tb_1_down.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"tb_1_up.png"];
UIImage *selectedImage1 = [UIImage imageNamed:@"tb_2_down.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"tb_2_up.png"];
UIImage *selectedImage2 = [UIImage imageNamed:@"tb_3_down.png"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"tb_3_up.png"];
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
self.tabBarController.tabBar.frame = CGRectMake(0, 430, 320, 50);
[self.tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:@"tb_tabBar_BG.png"]];
[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
有什么方法可以使“item1”的宽度为 108 而不是 106?!