Inder Kumar Rathore
Inder Kumar Rathore

Reputation: 40018

Change tint color of tabbar edit view controller

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.

This code was to change the color of more view controller, written in UITabBarController's subcalss

  override func viewDidLoad() {
    super.viewDidLoad()
    var view = self.moreNavigationController.topViewController.view as UITableView
    view.tintColor = Utilities.mainColor()
    view.separatorStyle = .None
  }

Suggestions are welcomed for both Objective-C or Swift

enter image description here

Upvotes: 2

Views: 1603

Answers (2)

Zahid
Zahid

Reputation: 562

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;
}

Upvotes: 0

Inder Kumar Rathore
Inder Kumar Rathore

Reputation: 40018

By trying below code worked for me

  override func viewDidLoad() {
    super.viewDidLoad()
    //this line helped me
    self.view.tintColor = Utilities.mainColor()
  }

Upvotes: 6

Related Questions