我的问题是我如何添加UITabBarController的childViewController的图标。我的代码是:
UITabBarController *tabBar=[[UITabBarController alloc]init];
MyUIViewController *mc=[[MyUIViewController alloc]init];
[tabBar addChildViewController:mc];
[self.navigationController pushViewController:tabBar animated:YES];
提前致谢。
答案 0 :(得分:1)
请试试这个
UITabBarController *tabController = [[UITabBarController alloc] init];
SomeViewController *viewController = [[SomeViewController alloc] initWithNibName:@"SomeViewController" bundle:nil];
[tabController setViewControllers:[NSArray arrayWithObject:viewController]];//Setting child viewController Array.
UITabBarItem *item = (UITabBarItem *)[tabController.tabBar.items objectAtIndex:0]; //for first view
[item setImage:[UIImage imageNamed:@"someImage.png"]]; //Image should be 23px X 23px ,I think so.
答案 1 :(得分:0)
我通过在MyUIViewController中添加属性和属性来解决这个问题:
@interface MyUIViewController{
UITabBarItem *tabBarItem;
}
@property (nonatomic, retain) UITabBarItem *tabBarItem;
然后用图像初始化它:
UITabBarController *tabBar=[[UITabBarController alloc]init];
MyUIViewController *mc=[[MyUIViewController alloc]init];
mc.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"MyTitle" image:[UIImage imageNamed:@"myImage.png"] tag:0];
[tabBar addChildViewController:mc];
[self.navigationController pushViewController:tabBar animated:YES];
答案 2 :(得分:0)
我刚刚发现桌面不区分大小写,但设备要求代码具有相同的alpha-numberic大小写(上/下)。确保文件的名称相同......直到案例(上/下)!
示例:
“first.png”磁盘上的文件名最好表示为 - > self.tabBarItem.image = [UIImage imageNamed:@“first”];
NOT - NOT --- NOT
self.tabBarItem.image = [UIImage imageNamed:@“First”];
首都'F'今天踢了我的屁股3个小时!由于这种疏忽,我今天失去了3小时的生命。希望这有助于其他人。