+ (UIImage *)imageFromColor:(UIColor *)color forSize:(CGSize)size withCornerRadius:(CGFloat)radius { CGRect rect = CGRectMake(0, 0, size.width, size.height); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); // Begin a new image that will be the new image with the rounded corners // (here with the size of an UIImageView) UIGraphicsBeginImageContext(size); // Add a clip before drawing anything, in the shape of an rounded rect [[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius] addClip]; // Draw your image [image drawInRect:rect]; // Get the image, here setting the UIImageView image image = UIGraphicsGetImageFromCurrentImageContext(); // Lets forget about that we were drawing UIGraphicsEndImageContext(); return image; }
Then add this to application:didFinishLaunchingWithOptions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
UIColor *backgroundColor = [UIColor greenColor];
// set the bar background color [[UITabBar appearance] setBackgroundImage:[AppDelegate imageFromColor:backgroundColor forSize:CGSizeMake(320, 49) withCornerRadius:0]];
// set the text color for selected state [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor, nil] forState:UIControlStateSelected]; // set the text color for unselected state [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor, nil] forState:UIControlStateNormal];
// set the selected icon color [[UITabBar appearance] setTintColor:[UIColor whiteColor]]; [[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]]; // remove the shadow [[UITabBar appearance] setShadowImage:nil];
// Set the dark color to selected tab (the dimmed background) [[UITabBar appearance] setSelectionIndicatorImage:[AppDelegate imageFromColor:[UIColor colorWithRed:26/255.0 green:163/255.0 blue:133/255.0 alpha:1] forSize:CGSizeMake(64, 49) withCornerRadius:0]];
Remark: Those icon images is in white color
Until this stage, you will get this,
by right it should shows white color, but somehow the icon image has changed.