【问题标题】:Draw horizontal linear gradient inside shape在形状内绘制水平线性渐变
【发布时间】:2012-12-12 22:15:32
【问题描述】:

我有以下代码根据给定的角度绘制一个三角形。
如何使用线性(水平)渐变填充此形状?

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    // Create Lines
    CGPoint startPt = CGPointMake(self.frame.size.width / 2.0, self.frame.size.height);

    CGContextSetLineWidth(context, width_);
    CGContextMoveToPoint(context, self.center.x, self.center.y);
    CGPoint addLines[] =
    {
        startPt,
        CGPointMake(radius_ * cos(angle_) + startPt.x, radius_ * sin(angle_) + startPt.y),
        CGPointMake(radius_ * cos(angle_) + startPt.x, startPt.y),
        startPt
    };

    CGContextAddLines(context, addLines, sizeof(addLines)/sizeof(addLines[0]));
    CGContextStrokePath(context);
}

【问题讨论】:

    标签: iphone ipad core-graphics


    【解决方案1】:

    使用形状作为剪切路径,然后用渐变填充形状的边界框。在那之后抚摸它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多