iOS TabBar更换选中的文字颜色

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:UIControlStateSelected];
];

你可能感兴趣的:(iOS TabBar更换选中的文字颜色)