1. 隐藏线条处理
CGRect rect = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]); CGContextFillRect(context, rect); UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); if (@available(iOS 13.0, *)) { UITabBarAppearance *tabBarAppearance = [self.tabBar.standardAppearance copy]; [tabBarAppearance setBackgroundImage:img]; [tabBarAppearance setShadowColor:[UIColor clearColor]]; [self.tabBar setStandardAppearance:tabBarAppearance]; } else { [self.tabBar setBackgroundImage:img]; [self.tabBar setShadowImage:img]; }
2. 更改UITababr的位置
之前是放在viewWillLayoutSubviews 里面的,但从iOS13开始,放到这个方法里面修改位置不再起作用。需要放到viewDidLayoutSubviews里面
- (void)viewDidLayoutSubviews{ [super viewDidLayoutSubviews];
CGRect tabFrame = self.tabBar.frame; tabFrame.size.height = 44; tabFrame.origin.y = 27; self.tabBar.frame = tabFrame; }