2012-07-09 78 views
1

我想在xcode 4.2中以编程方式在标签栏上添加图像。我尝试了很多次,但仍然无法完成我的任务。正如我已经问过的问题,但没有人给我满意的答案在Here 。提前致谢。度过快乐的一天。在xcode 4.2中以编程方式添加图像

回答

1

试试下面的代码

UITabBarItem *tabItem = [[[UITabBarItem tabBar] items] objectAtIndex:yourIndex]; 
    [tabItem setTitle:@"theTitle"]; 
    [tabItem setImage:[UIImage imageNamed:@"yourImage.png"]]; 
0

写这个方法在你的ViewController:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 

     self.tabBarItem.image = [UIImage imageNamed:@"image.png"]; 

    } 
    return self; 
} 
1

iOS 5的外观API,

UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"]; 
    [[UITabBar appearance] setBackgroundImage:tabBarBackground]; 

也看到这个thread,第二高的投票答案解释这两种情况下< 5.0 => 5.0的情况下。

相关问题