Search code examples
iosios7uitabbaruitabbaritem

Change UITabBarItem badge color in iOS 7.1


I am not able to modify the badge color of UItabBarItem in iOS 7.1, So I just added a UILabel to TabBar and set the colour I wanted and got that working in iOS 7.1. But I am not sure if this is the correct way of doing it. I will be submitting my app to appstore. Can someone guide me if there is a chance that my app is rejected because of this? Below is my code.

UILabel *badge=[[UILabel alloc]init];
badge.text = @"2";
badge.textAlignment=NSTextAlignmentCenter;
badge.frame=CGRectMake(122, 1, 20, 20);
badge.layer.cornerRadius=10;
badge.textColor=[UIColor whiteColor];
badge.backgroundColor=[UIColor greenColor];
[tabbar addSubview:badge];

Solution

  • You cannot modify the color of badge since it has not exposed to the user. You can only set the text as string

    @property(nonatomic,copy) NSString *badgeValue;    // default is nil
    

    What ever you are doing is fine.