And*_*rew 0 iphone core-graphics objective-c
到目前为止我有这个代码:
CGPoint midLeft = CGPointMake(0, additionalHeight);
CGPoint bottomCenter = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height);
CGPoint midRight = CGPointMake(self.bounds.size.width, additionalHeight);
CGPoint topRight = CGPointMake(self.bounds.size.width, 0);
CGPoint topLeft = CGPointMake(0, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(context, midLeft.x, midLeft.y);
CGContextAddLineToPoint(context, midRight.x, midRight.y);
CGContextAddLineToPoint(context, topRight.x, topRight.y);
CGContextAddLineToPoint(context, topLeft.x, topLeft.y);
CGContextClosePath(context);
Run Code Online (Sandbox Code Playgroud)
现在,它只是画了一个矩形,但我希望它能画出一个弧线,它向下延伸到bottomCenter,就像这个图像顶部的形状:

我已经尝试了CGContextAddArc和AddArcToPoint,并按照教程,但我无法弄清楚如何绘制这种弧.任何帮助表示赞赏.
看看这篇博文,它涵盖了弧形和路径.结果几乎与您的目标相同.
我的建议是完成他的整个Core Graphics 101系列,这真的很棒.
您也可以使用UIBezierPath.使用addQuadCurveToPoint:controlPoint:您可以轻松创建类似弧形的形状.
我没有测试下面的代码,但它应该创建这样的东西:

UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 10)];
[path addQuadCurveToPoint:CGPointMake(200, 10) controlPoint:CGPointMake(100, 5)];
[path addLineToPoint:CGPointMake(200, 0)];
[path addLineToPoint:CGPointMake(0, 0)];
[path closePath];
CGContextAddPath(context, path.CGPath);
[[UIColor redColor] set];
CGContextFillPath(context);
Run Code Online (Sandbox Code Playgroud)
希望这对任何帮助.
| 归档时间: |
|
| 查看次数: |
1395 次 |
| 最近记录: |