我正在尝试制作自定义标签栏。我使用了setFinishedSelectedImage:finishedUnselectedImage:方法,该方法删除了苹果在uitabbaritems上的默认光泽效果。这是我的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self customizeInterface];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UITabBarController *tabController = [[UITabBarController alloc] init];
UIViewController *viewController1 = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil];
UITabBarItem *tab1 = [[UITabBarItem alloc] initWithTitle:nil
image:[UIImage imageNamed:nil] tag:1];
[viewController1 setTabBarItem:tab1];
UITabBarItem *item = [[UITabBarItem alloc] init];
[tab1 setFinishedSelectedImage:[UIImage imageNamed:@"icon_news.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"icon_news.png"]];
_tabBarController.tabBarItem = item;
UIViewController *viewController2 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UITabBarItem *tab2 = [[UITabBarItem alloc] initWithTitle:nil
image:[UIImage imageNamed:nil] tag:2];
[viewController2 setTabBarItem:tab2];
UITabBarItem *item1 = [[UITabBarItem alloc] init];
[tab2 setFinishedSelectedImage:[UIImage imageNamed:@"icon_programme.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"icon_programme.png"]];
_tabBarController.tabBarItem = item1;
UIViewController *viewController3 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
UITabBarItem *tab3 = [[UITabBarItem alloc] initWithTitle:nil
image:[UIImage imageNamed:nil] tag:3];
[viewController3 setTabBarItem:tab3];
UITabBarItem *item2 = [[UITabBarItem alloc] init];
[tab3 setFinishedSelectedImage:[UIImage imageNamed:@"icon_map.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"icon_map.png"]];
_tabBarController.tabBarItem = item2;
UIViewController *viewController4 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
UITabBarItem *tab4 = [[UITabBarItem alloc] initWithTitle:nil
image:[UIImage imageNamed:nil] tag:4];
[tab4 setFinishedSelectedImage:[UIImage imageNamed:@"icon_venues.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"icon_venues.png"]];
[viewController4 setTabBarItem:tab4];
UITabBarItem *item3 = [[UITabBarItem alloc] init];
[item3 setFinishedSelectedImage:[UIImage imageNamed:@"icon_venues.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"icon_venues.png"]];
_tabBarController.tabBarItem = item3;
UIViewController *viewController5 = [[FourthViewController alloc] initWithNibName:@"FourthViewController" bundle:nil];
UITabBarItem *tab5 = [[UITabBarItem alloc] initWithTitle:nil
image:[UIImage imageNamed:nil] tag:5];
[viewController5 setTabBarItem:tab5];
UITabBarItem *item4 = [[UITabBarItem alloc] init];
[tab5 setFinishedSelectedImage:[UIImage imageNamed:@"icon_more.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"icon_more.png"]];
_tabBarController.tabBarItem = item4;
tabController.viewControllers = [NSArray arrayWithObjects:viewController1,
viewController2,
viewController3,
viewController4,
viewController5, nil];
self.window.rootViewController = tabController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)customizeInterface
{
UIImage* tabBarBackground = [UIImage imageNamed:@"navbar_bodyreal.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"navbar_object_current.png"]];
}
问题是标签栏上方的图标端口。 有什么想法吗?
由于
答案 0 :(得分:0)
您应该只设置相应UIViewConroller的tabbaritem属性。删除这些行。
_tabBarController.tabBarItem = itemx;
除了tabbar项目的最佳分辨率外,还应该是30x30像素。