我使用UIBezierPath
来画一条线。但是有一个错误
这是我的代码:
UIBezierPath *aPath = [UIBezierPath bezierPath];
[aPath moveToPoint:CGPointMake(100, 100)];
[aPath addLineToPoint:CGPointMake(200, 200)];
[aPath closePath];
aPath.lineWidth = 5;
[[UIColor redColor] setStroke];
[aPath stroke];
这是错误:
CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
最佳答案
而不是
[[UIColor redColor] setStroke];
使用
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
你也可以做同样的事情-
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
UIBezierPath *aPath;
aPath = [UIBezierPath bezierPath];
[aPath moveToPoint:CGPointMake(0, 0)];
[aPath addLineToPoint:CGPointMake(size*2, 0)];
[aPath addLineToPoint:CGPointMake(size, size*2)];
[aPath closePath];
shapeLayer.path = aPath.CGPath;
shapeLayer.strokeColor = [[UIColor redColor] CGColor];
shapeLayer.fillColor = color;
shapeLayer.lineWidth = width;
[self addSublayer:shapeLayer];
关于ios - 使用 UIBezierPath 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30024305/