方法一:
1、自定义tabbar,继承自系统的UITabBar。
@interface FTTabBar : UITabBar
2、除了添加tabbar按钮,需重写下面两个方法
- (CGSize)sizeThatFits:(CGSize)size {
size = [super sizeThatFits:size];
//iOS11以上系统,如果是刘海屏,底部tabbar的总高度小于90,就调整 tabbar的高度(或者直接赋值为死的高度83)
if(@available(iOS11.0, *)) {
float bottomInset = self.safeAreaInsets.bottom;
if(bottomInset >0 && size.height<50 && (size.height+ bottomInset <90)){
size.height+= bottomInset;
}
}
return size;
}
- (void)setFrame:(CGRect)frame {
if(self.superview) {
//如果tabbar 没有完全显示在其父视图,则调整其y坐标
if (frame.origin.y + frame.size.height != self.superview.frame.size.height{
frame.origin.y = self.superview.frame.size.height - frame.size.height;
}
}
[super setFrame:frame];
}
3、在自定义的UITabBarController里替换系统的tabbar
FTTabBar* tabbar = [[FTTabBar alloc] init];
[self setValue:tabbar forKey:@"tabBar"];
方法二:
在tabbarcontroller里面添加
self.tabBar.translucent = NO;
[UITabBar appearance].translucent = NO;
网友评论