我想更改标签栏控制器的编辑视图控制器的色调颜色。我已经设法改变了更多视图控制器的颜色,但没有得到这方面的线索。
此代码用于更改用UITabBarController
的子标记编写的更多视图控制器的颜色
override func viewDidLoad() {
super.viewDidLoad()
var view = self.moreNavigationController.topViewController.view as UITableView
view.tintColor = Utilities.mainColor()
view.separatorStyle = .None
}
答案 0 :(得分:6)
通过尝试以下代码为我工作
override func viewDidLoad() {
super.viewDidLoad()
//this line helped me
self.view.tintColor = Utilities.mainColor()
}
答案 1 :(得分:0)
您可以为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];
}
以下功能可用于手动着色图像
- (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;
}