[英]Xcode Add tabbar icon dynamically
我已经阅读了有关在app委托和界面构建器中添加tabbar图标的不同答案。我想在我的firtsviewcontroller中添加它们,因为我想从plist
读取图标图像名称。 建议这样做:
NSArray *viewControllerArray = nil;
viewController1 = <View Init Code>
viewController2 = <View Init Code>
viewController3 = <View Init Code>
1stNavController = [[UINavigationController alloc] initWithRootViewController:viewController1];
UIImage *img = [UIImage imageNamed:@"tab_home"];
[1stNavController .tabBarItem initWithTitle:@"Home" image:img tag:1];
但我不喜欢这样做,因为我觉得这不干净。 我想做类似以下的事情,但我不知道它为什么不起作用:
[[self.tabBarController.tabBar.items objectAtIndex:2] setIcon:[UIImage imageNamed:....]];
有解决方案吗
怎么样的:
NSArray *viewControllers = self.tabBarController.viewControllers;
((UIViewController*)viewControllers[0]).tabBarItem.image = [UIImage imageNamed:...];
((UIViewController*)viewControllers[1]).tabBarItem.image = [UIImage imageNamed:...];
((UIViewController*)viewControllers[2]).tabBarItem.image = [UIImage imageNamed:...];
((UIViewController*)viewControllers[3]).tabBarItem.image = [UIImage imageNamed:...];
((UIViewController*)viewControllers[4]).tabBarItem.image = [UIImage imageNamed:...];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.