我有以下代码根据给定的角度绘制三角形。
如何用线性(水平)渐变填充这个形状?
- (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);
}