【发布时间】:2012-01-26 15:33:25
【问题描述】:
我正在尝试自定义 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;
}
我在谷歌上搜索并找到了this tutorial,代码使用与我使用的相同的 API 并且按预期工作。 本文中的代码行为与我的一样,但是因为它们的背景颜色相同,所以会产生一种正确放置的错觉。
为什么finishedImageSelected 和unselected 和tab 标签不对齐?如何解决?
【问题讨论】:
标签: objective-c cocoa-touch ios5