UITabBarItem finishedImageSelected放置偏移标签栏

Fel*_*ano 5 cocoa-touch objective-c ios5

我正在尝试自定义UITabBarItem,但我的图像位置有问题.

在此输入图像描述

图像尺寸为81px x 49px,与UITabBar的高度相同.这是我设置图像的方式:

    // 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;
}
Run Code Online (Sandbox Code Playgroud)

我在google上搜索并找到了本教程,代码使用了与我使用相同的API并按预期工作. 本文中的代码就像我的代码一样,但由于它们的背景颜色相同,因此可以正确放置它的错觉.

为什么finishedImageSelected和unselected与选项卡选项卡不对齐?怎么解决?

Fel*_*ano 1

我找到了完成此操作的正确方法并发表了一篇文章:felipecypriano.com/2012/02/27/\xe2\x80\xa6

\n\n

基本上问题是 finishImage 是图标而不是图标和背景,可以通过调整 imageInset 属性与背景一起使用。

\n