记录iOS 13以上如何做tabbar的适配

<!-- run -->
<script>
window.ele.$notify({
          title: ‘提示‘,
          message: ‘加载成功‘,
          type: ‘success‘,
          position: ‘top-right‘
        });
</script>

适配自定义的UITabBarController,tabbar的字体颜色和选中时的背景以及字体颜色适配

  1. 字体消失的问题比较普遍,网上一搜就能找到
  2. 选中会默认带背景色这个,只发现在iPhone X机型上有
    UIColor *normalColor = [UIColor blackColor];
    UIColor *selectColor = [UIColor orangeColor];
    UIFont *font = [UIFont fontWithName:@"PingFang SC" size:10];
    NSDictionary *normalAttributes = @{
        NSForegroundColorAttributeName : normalColor,
        NSFontAttributeName : font
    };
    NSDictionary *selectedAttributes = @{
        NSForegroundColorAttributeName : selectColor,
        NSFontAttributeName : font
    };
    
    if (@available(iOS 13.0, *)) {
        //iOS 13不设置tintColor 字体颜色会消失
         self.tabBar.tintColor = selectColor;
        [self.tabBar setUnselectedItemTintColor:normalColor];
    }else{
        [[UITabBarItem appearance] setTitleTextAttributes:normalAttributes forState:UIControlStateNormal];
        [[UITabBarItem appearance] setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];
    }
    UIImage *barImg = [UIImage imageFromWithColor:[UIColor whiteColor]];
    UIImage *lineImg = [UIImage imageFromWithColor:RGBA(228,228,228,1)];
    // 这个不设置在iPhone X上会有默认的选中背景颜色 因为背景是白的 所以搞个白的图片
    self.tabBar.selectionIndicatorImage = barImg;
    self.tabBar.backgroundImage = barImg;
    self.tabBar.shadowImage = lineImg;

记录iOS 13以上如何做tabbar的适配

上一篇:Windows10磁盘占用100%和内存占用高


下一篇:ThinkPHP第五天(提交类型判定常量IS_POST等,错误页面种类,Model实例化方式,模板中使用函数,foreach循环,模板中.语法配置)