I want to change the tint color for the Edit view controller of tab bar controller. I have managed to change the color for more view controller but not getting clue for this.
By trying below code worked for me
override func viewDidLoad() {
super.viewDidLoad()
//this line helped me
self.view.tintColor = Utilities.mainColor()
}
You can set manually coloured images for tabBarItem
.
UIImage *defaultImage = [UIImage imageNamed:@"sports"];
defaultImage = [defaultImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//system tints wont apply on the default image
UIImage *selectedImage = [[UIImage imageNamed:@"sports"] imageWithColor:tintColor];
selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//System tints wont apply on this image
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Sports" image:defaultImage selectedImage:selectedImage];
}
Following function can be used to tint image manually
- (UIImage *)imageWithColor:(UIColor *)color1
{
UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0, self.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetBlendMode(context, kCGBlendModeNormal);
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextClipToMask(context, rect, self.CGImage);
[color1 setFill];
CGContextFillRect(context, rect);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}