【问题标题】:Draw a filled semi circle画一个实心半圆
【发布时间】:2012-03-30 21:47:23
【问题描述】:

在 UIView 中绘制填充(!)半圆的最佳方法是什么?我玩过 CGContextAddArc 函数,但它似乎没有提供填充。这是我喜欢画的 - 两个实心半圆。

【问题讨论】:

    标签: ios uiview core-graphics


    【解决方案1】:
    CGContextBeginPath(gc);
    CGContextAddArc(gc, 100, 100, 50, -M_PI_2, M_PI_2, 1);
    CGContextClosePath(gc); // could be omitted
    CGContextSetFillColorWithColor(gc, [UIColor cyanColor].CGColor);
    CGContextFillPath(gc);
    

    【讨论】:

    • 我不得不使用“CGContextSetFillColorWithColor”函数而不是“CGContextSetFillColor”。有了它,它工作得很好。谢谢!
    • 使用 CGContextRef gc = UIGraphicsGetCurrentContext(); 定义 cg 以使其工作
    • 你也可以使用 UIKit 来做到这一点。这就是我所做的。让 y:CGFloat = bounds.height / 2 让 x:CGFloat = bounds.width 让 c = CGPointMake(x, y) var maskPath = UIBezierPath(arcCenter: c, radius: x, startAngle: -(CGFloat(M_PI_2)), endAngle: (CGFloat(M_PI_2)), 顺时针: false) var maskLayer:CAShapeLayer = CAShapeLayer() maskLayer.frame = self.bounds maskLayer.path = maskPath.CGPath self.layer.mask = maskLayer
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    • 1970-01-01
    相关资源
    最近更新 更多