iOS修改tabbar高度&&修改tabbar的字体大小和位置

在继承自UITabBarController的自定义的tabbarController里实现

-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    CGRect frame = self.tabBar.frame;
    frame.size.height = tabbar原始高度+额外高度;
    frame.origin.y = self.view.frame.size.height-frame.size.height;
    self.tabBar.frame = frame;
}

遇到的问题
tabbar上的横线和白色背景在iOS13上不好隐藏,就是(_UIBarBackground上的两个imageView)
iOS修改tabbar高度&&修改tabbar的字体大小和位置_第1张图片
最后的解决方式
在tabbar上第一个显示的controller里的viewWillAppear里实现

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    UIImageView *imgView =  self.tabBarController.tabBar.subviews[0].subviews[0];
    if(CGRectGetHeight(imgView.frame) < ADDITIONHEIGHT){
        self.tabBarController.tabBar.subviews[0].subviews[0].hidden = YES;
        self.tabBarController.tabBar.subviews[0].subviews[1].hidden = YES;
    }
  }

其中self.tabBarController.tabBar.subviews[0].subviews[0]是横线,
self.tabBarController.tabBar.subviews[0].subviews[1]是白色背景。


//item是UITabBarItem
//修改字体颜色和大小
[item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#1a1a1a"],NSFontAttributeName:[UIFont
systemFontOfSize:13]} forState:UIControlStateNormal];
[item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#3fa0ef"],NSFontAttributeName:[UIFont
systemFontOfSize:13]} forState:UIControlStateSelected];
//文字向上移动
[item setTitlePositionAdjustment:UIOffsetMake(0, -2)];

你可能感兴趣的:(iOS)