Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在drawRect中绘制形状将删除渐变_Iphone_Ios_Objective C_Xcode_Ipad - Fatal编程技术网

Iphone 在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

我对核心图形非常陌生

基本上,我有一个绘制渐变背景的视图,我试图用另一个视图创建一个子类,然后在这个子类中绘制一个三角形

发生的情况是没有绘制渐变。我怀疑是因为我的子类正在drawRect中绘制三角形(super在其中绘制其渐变),我的子类正在重写drawRect方法,而super的被忽略

我怎样才能把梯度和三角形都画出来呢

下面是我的子类drawRect的代码

- (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'的开头:然后它将首先绘制渐变,然后绘制三角形