当我试图在UIButton
的Image
上叠加颜色时,出现了问题。
覆盖颜色出现在Image
下面。
这是我在我的drawRect
方法中拥有的代码(我已经子类化了UIButton
):
(void)drawRect:(CGRect)rect
{
CGRect bounds = self.imageView.bounds;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextTranslateCTM(context, 0.0, self.imageView.image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextClipToMask(context, bounds, [self.imageView.image CGImage]);
CGContextFillRect(context, bounds);
}
有什么建议可以让红色位于Image
的顶部吗?
paletteButton = [PaletteButton buttonWithType:UIButtonTypeCustom]; [paletteButton setImage:[UIImage imageNamed:@"98-palette.png"] forState:UIControlStateNormal]; paletteButton.frame = CGRectMake(110, 13, 24, 20);
- Matthew Wilson[super drawRect:]
呢? - user529758drawRect
) does not need to callsuper
. However, if you are subclassing a different view class, you should call[super drawRect:rect]
at some point in your implementation." 谢谢你指出这一点。 - Matthew Wilson