Change tint color of tabbar edit view controller

前端 未结 2 480
悲哀的现实
悲哀的现实 2021-01-22 03:34

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.

相关标签:
2条回答
  • 2021-01-22 03:45

    By trying below code worked for me

      override func viewDidLoad() {
        super.viewDidLoad()
        //this line helped me
        self.view.tintColor = Utilities.mainColor()
      }
    
    0 讨论(0)
  • 2021-01-22 03:52

    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;
    }
    
    0 讨论(0)
提交回复
热议问题