iOS 13适配UITabBar

作者: my_杨哥 | 来源:发表于2019-10-11 17:37 被阅读0次

UITabBar在iOS 13下会有问题,比如:
1、当push进入某个页面再pop回来时,tabBar的文字颜色就会变成系统自带的蓝色
2、隐藏tabBar分割线的方法已经失效了

下面针对这两个问题做下适配
1、在原有代码基础上直接添加如下代码

if (@available(iOS 13.0, *)) {
    UITabBarAppearance *appearance = [self.tabBar.standardAppearance copy];
    appearance.stackedLayoutAppearance.normal.titleTextAttributes = attribute;
    appearance.stackedLayoutAppearance.selected.titleTextAttributes = selectAttribute;
    self.tabBar.standardAppearance = appearance;
}

2、iOS 13之前,隐藏TabBar分割线的方法是

self.tabBar.backgroundImage = [UIImage imageWithColor:[UIColor whiteColor]];
self.tabBar.shadowImage = [UIImage new];

但在iOS 13中该方法无效,所以该做如下适配

if (@available(iOS 13.0, *)) {
    UITabBarAppearance *appearance = [self.tabBar.standardAppearance copy];
    appearance.backgroundImage = [UIImage imageWithColor:[UIColor whiteColor]];
    appearance.shadowColor = [UIColor clearColor];
    self.tabBar.standardAppearance = appearance;
} else {
    self.tabBar.backgroundImage = [UIImage imageWithColor:[UIColor whiteColor]];
    self.tabBar.shadowImage = [UIImage new];
}

相关文章

网友评论

    本文标题:iOS 13适配UITabBar

    本文链接:https://www.haomeiwen.com/subject/mrdxmctx.html