views:

432

answers:

3

hi i try to customize a uitabbar

i extended uitabbar item and now have a customized image in it but i cant get rid of the rounded edges.

code:

@interface CustomTabBarItem : UITabBarItem  
{
    UIImage *customHighlightedImage;
}

@property (nonatomic, retain) UIImage *customHighlightedImage;

@end

@implementation CustomTabBarItem

@synthesize customHighlightedImage;

- (void) dealloc
{
    [customHighlightedImage release]; customHighlightedImage=nil;
    [super dealloc];
}

-(UIImage *) selectedImage
{
    return self.customHighlightedImage;
}

@end

maybe somoen knows how to get rid of the rounded rect

around the image

thanks in advance alex

A: 

Set the cornerRadius on the view that has rounded corners to 0:

view.layer.cornerRadius = 0;

Also, you will probably need to add a #include to get the CALayer declarations:

#import <QuartzCore/QuartzCore.h>
progrmr
thanks. seems to work
Alex Milde
A: 

thanks solved it with custom tab bar items

NOT APPLE APPROVED YET.

goes into tabController1.m

    - (id) init
{   
    if(self = [super init])
    {
        CustomTabBarItem *tabItem = [[CustomTabBarItem alloc]
                                     initWithTitle:@"" image:nil tag:0];

        tabItem.customHighlightedImage=[UIImage imageNamed:TABBAR_TAB_4_ACTIVE];
        tabItem.customStdImage=[UIImage imageNamed:TABBAR_TAB_4_DEFAULT];       

        self.tabBarItem=tabItem;
        [tabItem release]; 
        tabItem=nil;    
    }
    return self;
}

cutom tabbaritem:

@interface CustomTabBarItem : UITabBarItem  
{
    UIImage *customHighlightedImage;
    UIImage *customStdImage;
}

@property (nonatomic, retain) UIImage *customHighlightedImage;
@property (nonatomic, retain) UIImage *customStdImage;

@end

#import "CustomTabBarItem.h"


@implementation CustomTabBarItem

@synthesize customHighlightedImage;
@synthesize customStdImage;

- (void) dealloc
{
    [customHighlightedImage release]; customHighlightedImage=nil;
    [customStdImage release]; customStdImage=nil;   
    [super dealloc];
}

-(UIImage *) selectedImage
{
    return self.customHighlightedImage;
}

-(UIImage *) unselectedImage
{
    return self.customStdImage;
}

@end
Alex Milde
Was this approved by Apple?
CVertex
Yes, It was approved. Search for "cinemaxx"
Alex Milde
Alex, How did you get the red / purple background to take up the entire space of the button when active?
Travis
I'm still getting the highlighted area behind my icon, and can't get the whole area to use the background.
Travis
sorry for the delay. i posted it as answer at the bottom
Alex Milde
Thanks ... I've got a CustomUITabBarController and CustomUITabBarItem that I've subclassed and trying to get working ... the only thing left to fix was the highlighting still showed up ... I'll try and use some of the solution below and if I get it working will put it up on Github.
Travis
A: 

This is dirty - but works and got approved:

  • resizes tabbar
  • use your own images in own size

in the tab controller setup

    tabController   = [[UITabBarController alloc] init];
tabController.view.frame = CGRectMake(0, 72, 320, 480 - (82));
tabController.delegate = self;
UIImageView *bgImageView;
bgImageView = [ [ UIImageView alloc ] initWithImage: [UIImage imageNamed:TABBAR_BACKGROUND]];
bgImageView.frame = CGRectMake(0, -11, 320, 60);

[[tabController tabBar] addSubview:bgImageView];
[[tabController tabBar] sendSubviewToBack:bgImageView];
tabController.tabBar.frame = CGRectMake(0, 460 - (59 + 52 - 11), 320, 49);
[bgImageView release];

[window addSubview:tabController.view];

in the tabviewcontroller1 init method

   - (id) init
{
    if(self = [super init])
    {       
        CustomTabBarItem *tabItem = [[CustomTabBarItem alloc]
                                     initWithTitle:@"" image:nil tag:0];

        tabItem.customHighlightedImage=[UIImage imageNamed:TABBAR_TAB_1_ACTIVE];
        tabItem.customStdImage=[UIImage imageNamed:TABBAR_TAB_1_DEFAULT];       

        self.tabBarItem=tabItem;
        [tabItem release]; 
        tabItem=nil;
    }

return self;
}

and the custom tab bar it looks like

    @interface CustomTabBarItem : UITabBarItem  
    {
        UIImage *customHighlightedImage;
        UIImage *customStdImage;
    }

    @property (nonatomic, retain) UIImage *customHighlightedImage;
    @property (nonatomic, retain) UIImage *customStdImage;

    @end

#import "CustomTabBarItem.h"


@implementation CustomTabBarItem

@synthesize customHighlightedImage;
@synthesize customStdImage;

- (void) dealloc
{
    [customHighlightedImage release]; customHighlightedImage=nil;
    [customStdImage release]; customStdImage=nil;   
    [super dealloc];
}

-(UIImage *) selectedImage
{
    return self.customHighlightedImage;
}

-(UIImage *) unselectedImage
{
    return self.customStdImage;
}

@end

IMPORTANT:

i'm pretty new to iphone development and pretty pretty shure you can do this way less hacky. furthermore i got approved with this which does NOT mean you autmoatically will, too.

Alex Milde