iOS modify the height of the tabbar && modify the font size and position of the tabbar

Implemented in a custom tabbarController inherited from UITabBarController

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

The problem encountered
. The horizontal line and white background on the tabbar are not easy to hide on iOS13, which is the
Insert picture description here
final solution (two imageViews on _UIBarBackground)
. Implemented in viewWillAppear in the first controller displayed on the tabbar

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

Among them, self.tabBarController.tabBar.subviews[0].subviews[0] is a horizontal line, and
self.tabBarController.tabBar.subviews[0].subviews[1] is a white background.


//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)];

Guess you like

Origin blog.csdn.net/qq_28285625/article/details/106356335
Recommended