0

我有一个 UITabbar,我正在自定义它的外观,它在 ios >5 中运行良好。但是当我在 iphone 4.3 模拟器中运行相同的时候,它会因为标签栏的外观而崩溃。

 for(UIViewController *tab in  tabBarController1.viewControllers)

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

我怎样才能在 iphone 4.3 模拟器中获得相同的外观?

任何帮助将是可观的......

4

2 回答 2

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

这将起作用。但请注意应用商店提交指南。尝试这个。

于 2013-04-02T07:44:50.320 回答
0

@Aman Aggarwal 给出了答案

苹果文档说

setTitleTextAttributes:forState:为给定的控件状态设置标题的文本属性。... 可用性适用于 iOS 5.0 及更高版本。

仅适用于 iOS 5.0 及更高版本

于 2013-04-02T07:12:04.967 回答