2015-06-14 59 views
0

enter image description hereUITabBar奇怪的高差

我想編程添加欄時,所看到的故事板圖像中的默認高度。任何想法如何得到它?以下是我用於將UITabBarController添加到我的應用程序的代碼。

- (void)setCustomTabBar 
{ 
    //TODO: Fix TabBar height 
    UITabBarController *tabBarController = [[UITabBarController alloc] init]; 

    TimelineVC *tvc = [[TimelineVC alloc] initWithNibName:@"TimelineVC" bundle:nil]; 
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:tvc]; 

    TimelineVC *tvc2 = [[TimelineVC alloc] initWithNibName:@"TimelineVC" bundle:nil]; 
    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:tvc2]; 
    tvc2.showFriends = true; 

    NotificationVC *nvc = [[NotificationVC alloc] initWithNibName:@"NotificationVC" bundle:nil]; 
    nav3 = [[UINavigationController alloc] initWithRootViewController:nvc]; 

    ProfileVC *pvc = [[ProfileVC alloc] initWithNibName:@"ProfileVC" bundle:nil]; 
    UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:pvc]; 

    [[UITabBar appearance] setTintColor:[UIColor whiteColor]]; 
    [[UITabBar appearance] setShadowImage:nil]; 
    [tabBarController setViewControllers:@[nav1, nav2, nav3, nav4]]; 
    tabBarController.selectedIndex = 0; 


    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    CGFloat tabBarWidth = screenRect.size.width/4; 

    [[UITabBar appearance] setBackgroundImage:[AppDelegate imageFromColor:[UIColor darkGrayColor] forSize:CGSizeMake(screenRect.size.width, 49) withCornerRadius:0]]; 
    [[UITabBar appearance] setSelectionIndicatorImage:[AppDelegate imageFromColor:[UIColor colorWithRed:26/255.0 green:163/255.0 blue:133/255.0 alpha:1] forSize:CGSizeMake(tabBarWidth, 49) withCornerRadius:0]]; 

    tabBarController.tabBar.translucent = NO; 

    UIImage *normalImage, *selectedImages; 
    normalImage =[UIImage imageNamed:@"TimeLineIcon"]; 
    selectedImages = [UIImage imageNamed:@"TimeLineIcon"]; 

    UIImage *normalImage2, *selectedImages2; 
    normalImage2 =[UIImage imageNamed:@"FriendsIcon"]; 
    selectedImages2 = [UIImage imageNamed:@"FriendsIcon"]; 

    UIImage *normalImage3, *selectedImages3; 
    normalImage3 =[UIImage imageNamed:@"NotificationIcon"]; 
    selectedImages3 = [UIImage imageNamed:@"NotificationIcon"]; 

    UIImage *normalImage4, *selectedImages4; 
    normalImage4 =[UIImage imageNamed:@"ProfileIcon"]; 
    selectedImages4 = [UIImage imageNamed:@"ProfileIcon"]; 


    //TODO: FOR LOOP 
    nav1.tabBarItem.selectedImage = [normalImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
    nav1.tabBarItem.image = [selectedImages imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
    nav1.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); 

    nav2.tabBarItem.selectedImage = [normalImage2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
    nav2.tabBarItem.image = [selectedImages2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
    nav2.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); 

    nav3.tabBarItem.selectedImage = [normalImage3 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
    nav3.tabBarItem.image = [selectedImages3 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
     nav3.tabBarItem.badgeValue = @"1"; 
    nav3.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); 

    nav4.tabBarItem.selectedImage = [normalImage4 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
    nav4.tabBarItem.image = [selectedImages4 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
    nav4.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); 

    self.window.rootViewController = tabBarController; 
    [self.window addSubview:tabBarController.view]; 

    [self enableSupportKit]; 
} 
+0

您可以添加用於添加欄的代碼嗎? – EmilDo

+0

將代碼添加到原始帖子。 –

回答

0
[self.tabBar setFrame:CGRectMake(self.tabBar.frame.origin.x, self.tabBar.frame.origin.y, self.tabBar.frame.size.width, self.tabBar.frame.size.height)]; 

這幫助了我。 希望它有幫助。

0

檢出你的launchImage。例如,它在你的模擬器中是正確的,但如果你使用你的iphone(我猜是iphone6)。刪除iphone6的launchimage,那麼你會發現這個問題。