我有我自己的UIButton
的子類。我在其上添加UIImageView
並添加圖像。我想用色調在圖像上繪製它,但它不起作用。在UIImageView上使用色調顏色
到目前爲止我有:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.clipsToBounds = YES;
self.circleView = [[UIView alloc]init];
self.circleView.backgroundColor = [UIColor whiteColor];
self.circleView.layer.borderColor = [[Color getGraySeparatorColor]CGColor];
self.circleView.layer.borderWidth = 1;
self.circleView.userInteractionEnabled = NO;
self.circleView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:self.circleView];
self.iconView = [[UIImageView alloc]init];
[self.iconView setContentMode:UIViewContentModeScaleAspectFit];
UIImage * image = [UIImage imageNamed:@"more"];
[image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.iconView.image = image;
self.iconView.translatesAutoresizingMaskIntoConstraints = NO;
[self.circleView addSubview:self.iconView];
...
和選擇:
- (void) setSelected:(BOOL)selected
{
if (selected) {
[self.iconView setTintColor:[UIColor redColor]];
[self.circleView setTintColor:[UIColor redColor]];
}
else{
[self.iconView setTintColor:[UIColor blueColor]];
[self.circleView setTintColor:[UIColor blueColor]];
}
}
我做了什麼錯? (圖像的顏色始終保持相同,因爲它是原)
當你創建** iconView **時,你可以使用'setTintColor'嗎? –
你的意思是在self.iconView = [UIImageView alloc] ...之後?是的,我可以,但它不起作用。 –
然後使用CGContext。也許你可以在這裏找到你的答案http://stackoverflow.com/a/19275079/1790571 –