0

我正在尝试制作自定义标签栏。我使用了 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"]];

}

问题是标签栏上方的图标端口。有任何想法吗?

谢谢

标签栏

4

1 回答 1

0

您应该只设置相应 UIViewConroller 的 tabbaritem 属性。删除这些行。

_tabBarController.tabBarItem = itemx;

除了标签栏项目的最佳分辨率应该是 30x30 像素。

http://www.idev101.com/code/User_Interface/sizes.html

于 2013-01-20T15:56:15.613 回答