2012-01-26 59 views
5

我試圖自定義UITabBarItem,但我有圖像的位置問題。UITabBarItem finishedImageSelected放置偏移標籤欄

enter image description here

的圖像尺寸爲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選項卡不對齊?如何解決它?

+0

我遇到了同樣的問題... – meadlai

回答

1

我發現了正確的方法來完成這個,並發表了一篇文章:felipecypriano.com/2012/02/27/…

基本上問題是,finishedImage是圖標不是圖標和背景,通過調整imageInset屬性可以與背景一起使用。