标签:
-(void)creatTabBarView { NSArray *imgArray=@[]; NSArray *selectImage=@[]; NSArray *names=@[]; for (int i=0; i<names.count; i++)
{ //Class 为类的泛型,泛指任意类,id为对象的泛指 Class class=NSClassFromString(names[i]); UIViewController *root=[[class alloc] init]; [self addChlildVc:root imageName:imgArray[i] selectedImageName:selectImage[i]]; } } // 给 tabBar 设置图片 - (void)addChlildVc:(UIViewController *)childVc imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName { // 设置图标 UIImage *image = [UIImage imageNamed:imageName]; image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; childVc.tabBarItem.image = image; // 设置选中的图标 UIImage *selectedImage = [UIImage imageNamed:selectedImageName]; selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; childVc.tabBarItem.selectedImage = selectedImage; //解决7.1版本图标不自适应 if ([UIParam getIOSVersion] <= 7.1) { childVc.tabBarItem.imageInsets = UIEdgeInsetsMake(30, 42, 18, 42); } UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:childVc]; [self addChildViewController:nav]; }
标签:
原文地址:http://www.cnblogs.com/SimonGao/p/4542177.html