[ios]UITabBarItem 更改图像的高度和宽度

我有没有标题和图像只有 UITabBarItem。我想知道我如何能改变图像大小所以它可以占用整个 UITabBarItem。

我找遍整个互联网,但什么也没找到。

我试过:

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main_Storyboard" bundle:nil];
UITabBarController *tabBarController = [storyBoard instantiateViewControllerWithIdentifier:@"tab"];
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];

tabBarItem1
.imageInsets = UIEdgeInsetsMake(0, -10, -6, -10);

但什么都没有改变。


从苹果文档的最大大小的一张图片在 TabBar 是 30 x 30 (60 x 60 的视网膜显示器)。

我不认为它是可能采取整个 TabBar 不拉伸图像的高度。我认为最好的解决办法是中心中使用 imageInset TabBar 的图像

tabBarItem1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

enter image description here

否则你可以玩这 imageInset 和拉伸图像像在截图中

tabBarItem1.imageInsets = UIEdgeInsetsMake(0, -10, -6, -10);

enter image description here

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  {


 
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;

 
UITabBar *tabBar = tabBarController.tabBar;
 
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
 
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
 
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];

 
//add image to tabbarItems

 tabBarItem1
.imageInsets = UIEdgeInsetsMake(0, -10, -6, -10);
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值