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;
    
  • 相关阅读:
    非常抱歉,全站内容审核中...
    jS代码总结(2)
    timestamp(数据库中的数据类型)
    jS代码总结(1)
    TextWriterTraceListener 和设计时属性支持文件xmta
    validating和validated的区别
    IoC和控制反转
    wince BindingSource
    简单网络传递加密数据
    C#不对称加密
  • 原文地址:https://www.cnblogs.com/wgb1234/p/14966884.html
Copyright © 2011-2022 走看看