我有以下代码,根据某个角度绘制一个三角形 如何使用线性(水平)渐变填充此形状?
- (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);
}
答案 0 :(得分:0)
将形状用作剪切路径,然后使用渐变填充形状的边界框。中风后呢。