UITabBarController图像未显示

时间:2016-09-04 11:46:02

标签: ios objective-c iphone

我正在使用UITabBarController,它有四个视图控制器。这些是Dashboard,ComposeMessage,PostMessage和Profile。我想在tabBarItem中使用图像。但问题是图像没有在UITabBar中显示。

    UITabBarController *customBar = [[UITabBarController alloc] init];

    DashboardViewController *social = [[DashboardViewController alloc]init];
    social.tabBarItem.image = [UIImage imageNamed:@"prifile_tab.png"];
    [customBar addChildViewController:social];

    ComposeMessageViewController *composeMessage = [[ComposeMessageViewController alloc]init];
    composeMessage.tabBarItem.image = [UIImage imageNamed:@"timer_post_tab.png"];
    [customBar addChildViewController:composeMessage];


    PostMessageViewController *postMessage = [[PostMessageViewController alloc] init];
    postMessage.tabBarItem.image = [UIImage imageNamed:@"timer_post_tab.png"];
    [customBar addChildViewController:postMessage];

    ProfileViewController *profile = [[ProfileViewController alloc] init];
    profile.tabBarItem.image = [UIImage imageNamed:@"timer_post_tab.png"];
    [customBar addChildViewController:profile];

    NSArray *tabBarArray = @[social,composeMessage,postMessage,profile];
    [customBar setViewControllers:tabBarArray];

    self.window.rootViewController = customBar;

2 个答案:

答案 0 :(得分:2)

Tabbar尺寸应该是这样的

@ 1x尺寸25 x 25(最大:48 x 32)

@ 2x尺寸50 x 50(最大:96 x 64)

@ 3x:尺寸75 x 75(最大值:144 x 96)

答案 1 :(得分:1)

只需检查你的图像尺寸是否正确..u应该只提供有效尺寸的图像或随机尺寸