简体   繁体   English

更改标签栏的色彩颜色编辑视图控制器

[英]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 这段代码是为了更改更多视图控制器的颜色,这些颜色写在UITabBarController的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 欢迎对Objective-C或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 . 您可以为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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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