0

I have a UITabbar and I m customizing its appearance which works fine in ios >5 .But when I run the same one in iphone 4.3 simulator it crashes because of tabbar appearance.

 for(UIViewController *tab in  tabBarController1.viewControllers)

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

How can I get the same appearance in iphone 4.3 simulator also ?

Any help would be appreciable...

Aaradhya
  • 559
  • 1
  • 5
  • 13

2 Answers2

0

@Aman Aggarwal gave the answer

The apple documentation says

setTitleTextAttributes:forState: Sets the title’s text attributes for a given control state. ... Availability Available in iOS 5.0 and later.

Only available in iOS 5.0 and later

HpTerm
  • 8,151
  • 12
  • 51
  • 67
  • Ok I found it is available in ios 5 or later.But there may be some alternative to achieve the same appearance but diferent attributes in 4.3.i want to know that? – Aaradhya Apr 02 '13 at 07:18
  • You will find workarounds for that I think, but if you need to publish on the app store I am note sure it will pass the submission process. – HpTerm Apr 02 '13 at 08:27
0

It needs a tricky implementation. Here is one. You can add buttons over the tab bar in your application. Its tricky but it works.

For this you have to subclass the UITabBarController.

Something like this

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

This will work. But beware about App store submission guide lines. Try this.

Mathew Varghese
  • 4,527
  • 2
  • 17
  • 26