zoukankan      html  css  js  c++  java
  • 记录iOS 13以上如何做tabbar的适配

    适配自定义的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;
    
  • 相关阅读:
    二分查找 【数组的二分查找】
    二分答案 [TJOI2007]路标设置
    队测 逆序对 permut
    【线段树】 求和
    状压DP Sgu223 骑士
    状压DP Poj3311 Hie with the Pie
    状压DP入门 传球游戏之最小总代价
    状压DP 小W选书籍
    状压DP [Usaco2008 Nov]mixup2 混乱的奶牛
    __gcd()用法
  • 原文地址:https://www.cnblogs.com/wgb1234/p/14966884.html
Copyright © 2011-2022 走看看