Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITabBarItem finishedImageSelected placed offsetting the tab bar

I'm trying to customize UITabBarItem but I'm having problems with the image's position.

enter image description here

The image size is 81px x 49px, the same height as the UITabBar. This is how I set the image:

    // AppDelegate
    BlocosController *blocos = [[[BlocosController alloc] initWithManagedObjectContext:moc] autorelease];
    UINavigationController *navBlocos = [[[UINavigationController alloc] initWithRootViewController:blocos] autorelease];
    tabBarController = [[UITabBarController alloc] initWithManagedObjectContext:moc];
    tabBarController.viewControllers = [NSArray arrayWithObjects: navData, navBlocos, navBairro, navAtualizar, nil];

// ...

// BlocosController.m

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tabBarItem = [[[UITabBarItem alloc] initWithTitle:TITLE image:nil tag:10] autorelease];
        [[self tabBarItem] setFinishedSelectedImage:[UIImage imageNamed:@"tab_bar_blocos_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_bar_blocos_unselected"]];
    }
    return self;
}

I've search on google and found this tutorial, the code uses the same API as I use and works as expected. The code in this article behaves just like mine, but since their background is the same color there's a illusion of it been correctly placed.

Why is the finishedImageSelected and the unselected are placed unaligned with the tab tab? How to fix it?

like image 202
Felipe Cypriano Avatar asked Nov 13 '22 11:11

Felipe Cypriano


1 Answers

I've found the correct way to accomplish this and made a post: felipecypriano.com/2012/02/27/….

Basically the problem is that finishedImage is the icon not the icon and the background, it's possible to use with the background by adjusting the imageInset property.

like image 83
Felipe Cypriano Avatar answered Nov 16 '22 04:11

Felipe Cypriano