简体   繁体   English

无法在iOS5中自定义标签栏

[英]Can't customise tab bar in iOS5

I have a tab in iOS 5 and wish to have a image for the TabBarButton for the selected and on not-selected states. 我在iOS 5中有一个标签,希望在选定状态和未选定状态下都有TabBarButton的图像。 Here is the code: 这是代码:

 BOOL isIOS5 = [[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0;

    if(isIOS5)
    {
        //[tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:@"Tab-bg"]];
       // [tabBarController.tabBar setSelectionIndicatorImage:[UIImage imageNamed:@"Cell-bg"]];

         [[tabBarController.tabBar.items objectAtIndex:0] setFinishedSelectedImage:[UIImage imageNamed:@"list-menu-selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"list-menu"]];
        [[tabBarController.tabBar.items objectAtIndex:1] setFinishedSelectedImage:[UIImage imageNamed:@"gallery-menu-selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"gallery-menu"]];
        [[tabBarController.tabBar.items objectAtIndex:2] setFinishedSelectedImage:[UIImage imageNamed:@"map-menu-selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"map-menu"]];
        [[tabBarController.tabBar.items objectAtIndex:3] setFinishedSelectedImage:[UIImage imageNamed:@"submit-menu-selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"submit-menu"]];
        [[tabBarController.tabBar.items objectAtIndex:4] setFinishedSelectedImage:[UIImage imageNamed:@"search-menu-selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"search-menu"]];
    }

ie the images are 44px height for non-retina display so they should be enough to fill the space 也就是说,对于非视网膜显示,图像的高度为44px,因此它们应足以填充空间

The problem is that the images dont't go from top to bottom: there remains some space not filled at the bottom of the tabbar. 问题在于图像不会从上到下移动:标签栏的底部还没有填充一些空间。 Has anyone ever had this problem? 有人遇到过这个问题吗?

正如您在此处看到的那样,它是49: http//www.idev101.com/code/User_Interface/sizes.html

If you're already checking for specific cases like iOS 5, might be easiest just to create images that match the exact pixel height of the bar already. 如果您已经在检查诸如iOS 5之类的特定情况,则可能最简单的方法就是创建与条形的确切像素高度匹配的图像。 Alternatively you can look at what properties you can set on the tabBar.item itself. 或者,您可以查看可以在tabBar.item本身上设置的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM