zoukankan      html  css  js  c++  java
  • OC

    系统默认是 蓝色。但是当 tabbarItem的 选中图标改成了 灰色后,我们也希望把 文字改成 灰色。这个时候就用到了“

    setTitleTextAttributes” 方法。

    可以在  “ UITabBarItem ” 类的父类 “ UIBarItem ” 类中找到下面这个方法:

    /* You may specify the font, text color, and shadow properties for the title in the text attributes dictionary, using the keys found in NSAttributedString.h.

     */

    - (void)setTitleTextAttributes:(nullable NSDictionary<NSString *,id> *)attributes forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

    这个方法是用来改变 文字的颜色。 可以在 “NSAttributedString.h” 类中找到 Keys.

        // 默认
        NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
        attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
        attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
        [essenceVC.tabBarItem setTitleTextAttributes:attrs forState:UIControlStateNormal];
        
        // 选中
        NSMutableDictionary *attrSelected = [NSMutableDictionary dictionary];
        attrSelected[NSFontAttributeName] = [UIFont systemFontOfSize:12];
        attrSelected[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
        [essenceVC.tabBarItem setTitleTextAttributes:attrSelected forState:UIControlStateNormal];
    setTitleTextAttributes 方法 是 “UI_APPEARANCE_SELECTOR ”,以后只要看到 方法名后面有 “UI_APPEARANCE_SELECTOR ”,就代表可以使用 "[UITabBarItem appearance];" 中的 “appearance”。统一设置。

    比如说:tabbarController 上面有5个tabbarItem 。这个时候可以写成:
        // 默认
        NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
        attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
        attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
        // 选中
        NSMutableDictionary *attrSelected = [NSMutableDictionary dictionary];
        attrSelected[NSFontAttributeName] = [UIFont systemFontOfSize:12];
        attrSelected[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
        
    
        UITabBarItem *item = [UITabBarItem appearance];
        [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
        [item setTitleTextAttributes:attrSelected forState:UIControlStateNormal];
    
    

    这样写完,可以保证5各tabbar的 文字都是统一的。

     
  • 相关阅读:
    Strom在本地运行调试出现的错误
    能否通过六面照片构建3D模型?比如人脸,全身的多角度照片,生成3D模型。?
    怎么识别自己的眼型?眼型图片参照
    用opencv检测人眼并定位瞳孔位置
    仿射变换
    二维图像的三角形变换算法解释
    Labeled Faces in the Wild 人脸识别数据集
    【图像处理】计算Haar特征个数
    人脸识别技术大总结(1):Face Detection & Alignment
    基于Policy Gradient实现CartPole
  • 原文地址:https://www.cnblogs.com/iOS363536404/p/5590546.html
Copyright © 2011-2022 走看看