iOS UITabBarController底部tabbar的item间距设置

UITabBarController的item间距能不能设置 

UITabBarController的每个item不设title的话,那个title还是会占据着最下面那一行的位置,该怎么去隐藏它让那个位置空出来

UITabBarController的item间距能不能设置,因为我发现只有3个item的时候都集中在中间那块,我想把它们的间距设置大一点

可以换一种方案,调整UIBarItem的imageInsets使图片居中 (我假设你真正想要的是让图片居中显示)

[self.tabBarItem setImageInsets:UIEdgeInsetsMake(10, 0, -10, 0)];

很重要的一点,设置UIEdgeInsetsMaketopbottom属性为相反数,
否则会发生点击item后拖动,item会发生形变。

//
//  RootViewController.m
//  test_storyBoard_ipad
//
//  Created by admin on 3/4/16.
//  Copyright © 2016 jeffasd. All rights reserved.
//

#import "RootViewController.h" //父类 UITabbarController

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
//    [self.tabBarItem setImageInsets:UIEdgeInsetsMake(10, 0, -10, 0)];
    
//    [self.tabBarItem setImageInsets:UIEdgeInsetsMake(30, 0, -30, 0)];
    
//    self.tabBar.items
    
    for (UITabBarItem *item in self.tabBar.items) {
        
//        UIEdgeInsets insets = {top, left, bottom, right};
        
//        [item setImageInsets:UIEdgeInsetsMake(10, 0, -10, 0)];
        
//        [item setImageInsets:UIEdgeInsetsMake(0, -30, 0, 30)];
        
        [item setImageInsets:UIEdgeInsetsMake(0, -30, 0, 30)];
        
    }
    
//    UITabBarButton;
//    UIButton;
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.bounds = CGRectMake(0, 0, 30, 80);
    button.backgroundColor = [UIColor redColor];
    button.center = CGPointMake(self.tabBar.frame.size.width/2, self.tabBar.frame.size.height/2 - 20);
    
//    [self.tabBar setShadowImage:IMG(@"transparent")];
    
//    button.center = self.tabBar.center;
    
    [self.tabBar addSubview:button];
    
    NSLog(@"self tabBar is %@", self.tabBar.subviews);
    
//    [self.tabBar.superview addSubview:button];
    
//    [[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];
    
//    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc]init]];
    
    self.tabBar.backgroundImage = [[self class] createImageWithColor:[UIColor cyanColor]];
    self.tabBar.shadowImage = [UIImage new];
    
}

/**
 * 将UIColor变换为UIImage
 *
 **/
+ (UIImage *)createImageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return theImage;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end




https://segmentfault.com/q/1010000000362020
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值