记录iOS 13以上如何做tabbar的适配
<!-- run -->
<script>
window.ele.$notify({
title: ‘提示‘,
message: ‘加载成功‘,
type: ‘success‘,
position: ‘top-right‘
});
</script>
适配自定义的UITabBarController
,tabbar的字体颜色和选中时的背景以及字体颜色适配
- 字体消失的问题比较普遍,网上一搜就能找到
- 选中会默认带背景色这个,只发现在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;