简体   繁体   中英

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

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM