Iphone 在drawRect中绘制形状将删除渐变
我对核心图形非常陌生 基本上,我有一个绘制渐变背景的视图,我试图用另一个视图创建一个子类,然后在这个子类中绘制一个三角形 发生的情况是没有绘制渐变。我怀疑是因为我的子类正在drawRect中绘制三角形(super在其中绘制其渐变),我的子类正在重写drawRect方法,而super的被忽略 我怎样才能把梯度和三角形都画出来呢 下面是我的子类drawRect的代码Iphone 在drawRect中绘制形状将删除渐变,iphone,ios,objective-c,xcode,ipad,Iphone,Ios,Objective C,Xcode,Ipad,我对核心图形非常陌生 基本上,我有一个绘制渐变背景的视图,我试图用另一个视图创建一个子类,然后在这个子类中绘制一个三角形 发生的情况是没有绘制渐变。我怀疑是因为我的子类正在drawRect中绘制三角形(super在其中绘制其渐变),我的子类正在重写drawRect方法,而super的被忽略 我怎样才能把梯度和三角形都画出来呢 下面是我的子类drawRect的代码 - (void)drawRect:(CGRect)rect { // get the current content CGC
- (void)drawRect:(CGRect)rect
{
// get the current content
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat buttonHeight = self.bounds.size.height;
CGFloat buttonWidth = self.bounds.size.width;
// draw triangle
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(buttonWidth / 2, buttonHeight * .75)];
[path addLineToPoint:CGPointMake(buttonWidth * .75, buttonHeight * .25)];
[path addLineToPoint:CGPointMake(buttonWidth * .25,buttonHeight * .25)];
CGContextAddPath(context, path.CGPath);
CGContextClip(context);
[_arrowColor set];
[path fill];
}
如果调用
[super-drawRect:rect]
在子类'drawRect'的开头:然后它将首先绘制渐变,然后绘制三角形