如何在iOS(Xcode 4.2)中以编程方式在标签栏上添加图像?
我已经问过问题,但没有在Could not set tab bar image in Xcode 4.2 Programmatically得到满意答案。
答案 0 :(得分:1)
iOS 5外观api,
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
另见thread,第二高的投票回答解释了两个案例< 5.0和=> 5.0案例。
答案 1 :(得分: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;
}
答案 2 :(得分:0)
尝试以下代码
UITabBarItem *tabItem = [[[UITabBarItem tabBar] items] objectAtIndex:yourIndex];
[tabItem setTitle:@"theTitle"];
[tabItem setImage:[UIImage imageNamed:@"yourImage.png"]];