ios 4.3中的tabbar项目外观

时间:2013-04-02 07:00:21

标签: iphone ipad ios4 xcode4.5

我有一个UITabbar,我自定义它的外观在ios> 5中工作正常。但是当我在iphone 4.3模拟器中运行相同的一个时,它会因tabbar外观而崩溃。

 for(UIViewController *tab in  tabBarController1.viewControllers)

        {
            [tab.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                    [UIFont fontWithName:@"Arial" size:16.0], UITextAttributeFont, nil]
                                          forState:UIControlStateNormal];
        }

如何才能在iphone 4.3模拟器中获得相同的外观?

任何帮助都会很明显......

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

它需要一个棘手的实现。这是一个。您可以在应用程序的选项卡栏上添加按钮。它很棘手,但它确实有效。

为此你必须继承UITabBarController

像这样的东西

<强> BaseViewController.h

@interface BaseViewController : UITabBarController
{
}

// Create custom UIButtons and add it to the tab bar
-(void) addButtons;

@end

<强> BaseViewController.m

#import "BaseViewController.h"
#import "AppDelegate.h"

@implementation BaseViewController
// Create custom UIButtons and add it to the tab bar

-(void) addButtons
{
    UIImageView *backgroundImage    =   [[UIImageView alloc] initWithFrame: CGRectMake(20, 0, 330, 60)];
    [backgroundImage setImage: [UIImage imageNamed: @"bottom.png"]];
    [backgroundImage setCenter: self.tabBar.center];
    [self.view addSubview: backgroundImage];
    [backgroundImage release];

    UIButton    *firstTabbarButton  =   [UIButton buttonWithType: UIButtonTypeCustom];
    firstTabbarButton.frame = CGRectMake(20.0, 52.0, 68, 49);
    [firstTabbarButton setBackgroundImage:[UIImage imageNamed: @"home_normal.png"] forState:UIControlStateNormal];
    [firstTabbarButton setBackgroundImage:[UIImage imageNamed: @"home_normal.png"] forState:UIControlStateHighlighted];
    [firstTabbarButton setBackgroundImage:[UIImage imageNamed: @"home.png"] forState:UIControlStateSelected];
    [firstTabbarButton addTarget: self action: @selector(goButtonClicked:) forControlEvents: UIControlEventTouchUpInside];
    [firstTabbarButton setCenter: CGPointMake(33, self.tabBar.center.y)];
    [firstTabbarButton setTag: 1000];
    [firstTabbarButton setAdjustsImageWhenHighlighted: NO];
    [self.view addSubview: firstTabbarButton];

    UIButton    *secondTabbarButton  =   [UIButton buttonWithType: UIButtonTypeCustom];
    secondTabbarButton.frame = CGRectMake(20.0, 52.0, 68, 49);
    [secondTabbarButton setBackgroundImage:[UIImage imageNamed: @"lab_normal.png"] forState:UIControlStateNormal];
    [secondTabbarButton setBackgroundImage:[UIImage imageNamed: @"lab_normal.png"] forState:UIControlStateHighlighted];
    [secondTabbarButton setBackgroundImage:[UIImage imageNamed: @"lab_hover.png"] forState:UIControlStateSelected];
    [secondTabbarButton addTarget: self action: @selector(goButtonClicked:) forControlEvents: UIControlEventTouchUpInside];
    [secondTabbarButton setCenter: CGPointMake(96, self.tabBar.center.y)];
    [secondTabbarButton setTag: 1001];
    [secondTabbarButton setAdjustsImageWhenHighlighted: NO];
    [self.view addSubview: secondTabbarButton];

    UIButton    *thirdTabbarButton  =   [UIButton buttonWithType: UIButtonTypeCustom];
    thirdTabbarButton.frame = CGRectMake(20.0, 52.0, 68, 49);
    [thirdTabbarButton setBackgroundImage:[UIImage imageNamed: @"others.png"] forState:UIControlStateNormal];
    [thirdTabbarButton setBackgroundImage:[UIImage imageNamed: @"others.png"] forState:UIControlStateHighlighted];
    [thirdTabbarButton setBackgroundImage:[UIImage imageNamed: @"others_hover.png"] forState:UIControlStateSelected];
    [thirdTabbarButton addTarget: self action: @selector(goButtonClicked:) forControlEvents: UIControlEventTouchUpInside];
    [thirdTabbarButton setCenter: CGPointMake(287, self.tabBar.center.y)];
    [thirdTabbarButton setTag: 1004];
    [thirdTabbarButton setAdjustsImageWhenHighlighted: NO];
    [self.view addSubview: thirdTabbarButton];

    UIButton    *forthTabbarButton  =   [UIButton buttonWithType: UIButtonTypeCustom];
    forthTabbarButton.frame = CGRectMake(20.0, 52.0, 68, 49);
    [forthTabbarButton setBackgroundImage:[UIImage imageNamed: @"history_normal.png"] forState:UIControlStateNormal];
    [forthTabbarButton setBackgroundImage:[UIImage imageNamed: @"history_normal.png"] forState:UIControlStateHighlighted];
    [forthTabbarButton setBackgroundImage:[UIImage imageNamed: @"history.png"] forState:UIControlStateSelected];
    [forthTabbarButton addTarget: self action: @selector(goButtonClicked:) forControlEvents: UIControlEventTouchUpInside];
    [forthTabbarButton setCenter: CGPointMake(223, self.tabBar.center.y)];
    [forthTabbarButton setAdjustsImageWhenHighlighted: NO];
    [forthTabbarButton setTag: 1003];
    [self.view addSubview: forthTabbarButton];

    UIImage *centerImage  =   [UIImage imageNamed:@"go_btn.png"];
    UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0.0, 52.0, 62, 62);
    [button setTag: 1002];
    [button setBackgroundImage:centerImage forState:UIControlStateNormal];
    [button setBackgroundImage:highlightImage forState:UIControlStateSelected];
    [button addTarget: self action: @selector(goButtonClicked:) forControlEvents: UIControlEventTouchUpInside];

    CGFloat heightDifference = button.frame.size.height - self.tabBar.frame.size.height;

    if (heightDifference < 0)
        button.center = self.tabBar.center;
    else
    {
        CGPoint center = self.tabBar.center;
        center.y = center.y - heightDifference/2.0;
        button.center = center;
    }

    [self.view addSubview:button];
}

@end

这会奏效。但要注意App商店提交指南。试试这个。