I'm trying to customize UITabBarItem but I'm having problems with the image's position.
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With