iOS-使用代码CGImage调节tabBar上按钮图片的大小

tabBar 上button过大 


  

        

  
    NSArray *EnglishTitleArray = @[@"toutiao",@"shequ",@"xuanche",@"jiangjia",@"wode"];
    
    static NSInteger markIndex = 0;
    
    //遍历tabBar视图控制器
    for (UINavigationController *navigation in self.viewControllers) {
        UIViewController *vc = navigation.viewControllers.firstObject;
        
        //拼装图片名
        NSString *normalImageName = [NSString stringWithFormat:@"btn_%@_nor.9",EnglishTitleArray[markIndex]];
        NSString *checkedImageName = [NSString stringWithFormat:@"btn_%@_select.9",EnglishTitleArray[markIndex]];
        
        //get图片 调节图片大小
        UIImage *normalImage = [UIImage imageWithCGImage:[UIImage imageNamed:normalImageName].CGImage scale:2 orientation:UIImageOrientationUp];
        
        UIImage *checkedImage = [UIImage imageWithCGImage:[UIImage imageNamed:checkedImageName].CGImage scale:2 orientation:(UIImageOrientationUp)];
        
        
        //创建tabBarItem
        UITabBarItem *item = [[UITabBarItem alloc]initWithTitle:nil image:normalImage selectedImage:checkedImage];
        vc.tabBarItem = item;
        
        //调节button位置
        vc.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5,0);

        markIndex ++;
    }

代码调整过后效果


你可能感兴趣的:(iOS-使用代码CGImage调节tabBar上按钮图片的大小)