我正在尝试向tabViewController
添加自定义图片。它对我来说很好;这是我正在使用的代码:
[[AppDelegate.Tabctrl.tabBar.items objectAtIndex:0] setFinishedSelectedImage:[UIImage imageNamed:@"Home-Select.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Home.png"]];
[[AppDelegate.Tabctrl.tabBar.items objectAtIndex:1] setFinishedSelectedImage:[UIImage imageNamed:@"MyTc-Select.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"MyTc.png"]];
[[AppDelegate.Tabctrl.tabBar.items objectAtIndex:2] setFinishedSelectedImage:[UIImage imageNamed:@"Browse-Select.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Browse.png"]];
[[AppDelegate.Tabctrl.tabBar.items objectAtIndex:3] setFinishedSelectedImage:[UIImage imageNamed:@"Instore-Select.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Instore.png"]];
[[AppDelegate.Tabctrl.tabBar.items objectAtIndex:4] setFinishedSelectedImage:[UIImage imageNamed:@"More-Select.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"More.png"]];
图片不适合标签栏(我无法发布图片)。 有一些设计问题吗?我该如何解决这个问题?
答案 0 :(得分:0)
图像的宽度应为(320 /标签栏项目数)。这意味着320/4。
答案 1 :(得分:0)
参考这个 Add custom image to UITabBarController
UITabBarItem *tabBarItem1 = [AppDelegate.Tabctrl.tabBar.items objectAtIndex:0];
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@“Home-Select.png”] withFinishedUnselectedImage:[UIImage imageNamed:@“Home.png”]];
tabBarItem1.imageInsets = UIEdgeInsetsMake(6,0,-6,0);
答案 2 :(得分:0)
UITabBarItem *tabBarItem1 = [AppDelegate.Tabctrl.tabBar.items objectAtIndex:0];
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"unselected.png"]];
此外,您还需要确保图像的大小适合空间。