Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.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
Ios drawRect中的CGContextClip不工作_Ios_Core Graphics_Drawrect_Cgcontext - Fatal编程技术网

Ios drawRect中的CGContextClip不工作

Ios drawRect中的CGContextClip不工作,ios,core-graphics,drawrect,cgcontext,Ios,Core Graphics,Drawrect,Cgcontext,我一直试图剪辑我的视图,使其指向右侧,但由于某些原因,它不起作用 以下是我在drawRect中的代码: CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextMoveToPoint(ctx, width - 20.0, 0.0); CGContextAddLineToPoint(ctx, width, height / 2.0); CGContextAddLineToPoint(ctx, width - 20.0, height)

我一直试图剪辑我的视图,使其指向右侧,但由于某些原因,它不起作用

以下是我在drawRect中的代码:

CGContextRef ctx = UIGraphicsGetCurrentContext();

CGContextMoveToPoint(ctx, width - 20.0, 0.0);
CGContextAddLineToPoint(ctx, width, height / 2.0);
CGContextAddLineToPoint(ctx, width - 20.0, height);

[[UIColor blackColor] setStroke];
CGContextStrokePath(ctx);

CGContextClip(ctx);
我只是把笔划的路径,看看它是否工作。 笔划工作正常,但CGContextClip()无法(没有笔划功能)挽救我的生命

请帮帮我!!提前谢谢

使用
CoreGraphics

-(void) drawRect:(CGRect)rect {
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextMoveToPoint(ctx, CGRectGetMinX(rect), CGRectGetMinY(rect));
    CGContextAddLineToPoint(ctx, CGRectGetMaxX(rect)/2, CGRectGetMaxY(rect));
    CGContextAddLineToPoint(ctx, CGRectGetMaxX(rect), CGRectGetMinY(rect));
    [[UIColor redColor] setFill];
    CGContextFillPath(ctx);
}

你想要像traingle这样的东西吗?是的,我正在尝试制作一个右尖的矩形,就像那些允许你在深入界面中导航的东西,你可以使用
CGContext
简单地绘制一个矩形。你为什么要剪掉这条路?哦。。。。。。。我只是懒散了,我想我将只剪辑现有的矩形。我是编程新手,所以我没有意识到。你的意思是,drawRect是绘制rect的地方,所以我应该继续用我的配置绘制矩形?谢谢谢谢我从你的评论中得到了暗示,所以我把它整理好了:)非常感谢