UITabBarItem

UITabBarItem : UIBarItem

初始化

由于是放在 Bar 上,存在 tintColor,没有 selectedImage 也是可以的
也可以使用选中图片以原图显示,来避免 tintColor 的影响

    UITabBarItem *barItem1 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemHistory tag:9002];
    // 系统提供很多,枚举不详细举例了
    
    UITabBarItem *barItem2 = [[UITabBarItem alloc] initWithTitle:@"标题" image:[UIImage imageNamed:@""] tag:9002];
    UITabBarItem *barItem3 = [[UITabBarItem alloc] initWithTitle:@"标题" image:[UIImage imageNamed:@"tab_3_normal"] selectedImage:[UIImage imageNamed:@"tab_3_selected"]];

属性调整

    // 选中图片
    barItem2.selectedImage = [UIImage imageNamed:@"tab_2_selected"];

    // 文本偏移
    barItem2.titlePositionAdjustment = UIOffsetMake(10, 10);

标记 badge

    barItem2.badgeValue = @"999";
    
    // iOS 10 新增 
    barItem2.badgeColor = [UIColor redColor];
    [barItem2 setBadgeTextAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12],
                                       NSForegroundColorAttributeName: [UIColor greenColor]
                                       } forState:UIControlStateNormal];
    NSDictionary *dic = [barItem2 badgeTextAttributesForState:UIControlStateNormal];