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

tabBar 上button过大 


  151859_6kyh_2633043.png

        

  
    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 ++;
    }

代码调整过后效果

152046_r88s_2633043.png


转载于:https://my.oschina.net/ArtemisFang/blog/617982

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值