0
我有下面的代碼,根據某個給定的角度繪製一個三角形。
如何用線性(水平)漸變填充此形狀?繪製形狀內的水平線性漸變
- (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);
}