创建TabBar

-(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]; }

 

你可能感兴趣的:(tab)