【问题标题】:Can't set fill color to CGRect/path quartz无法将填充颜色设置为 CGRect/path 石英
【发布时间】:2013-02-27 21:29:47
【问题描述】:

我想制作一个矩形并用颜色填充。但是我的代码不起作用(没有出现矩形)。请告诉我这段代码有什么问题?

- (void)drawRect:(CGRect)rect
{
context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 84, 84, 84, 1);
firstTower = CGRectMake(20, 20, 50, 200);
CGContextDrawPath(context, kCGPathFillStroke);

if (_touchHasBegun)
{
    context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 2.0);
    CGContextSetRGBStrokeColor(context, 0, 34, 102, 1);                    
    CGContextSetRGBFillColor(context, 135, 206, 250, 0.25);
    rectangle = CGRectMake(1, 1, 500, 500);
    CGContextAddArc(context, pointWhereUserClickedX, pointWhereUserClickedY, 50, 0, 2*3.14159265359, YES);
    CGContextDrawPath(context, kCGPathFillStroke);


}

}

if 语句是一个圆圈。

【问题讨论】:

  • “它不起作用”是什么意思?
  • 我实际上通过删除第一个 CGCOntextDrawPath 行解决了这个问题。但请查看更新后的问题,有新问题。

标签: objective-c core-graphics


【解决方案1】:

矩形没有出现,因为您没有将它添加到上下文中。您创建了一个 CGRect 并将其分配给 firstTower 变量,但您从未告诉上下文有关它的内容。

你可能想添加

CGContextAddRect(context, firstTower);

分配给firstTower之后。

同样,您不会在第二次抽奖时添加 rectangle 值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    • 1970-01-01
    • 2018-06-09
    • 1970-01-01
    • 2019-01-16
    • 2017-04-19
    相关资源
    最近更新 更多