1
我在視圖上繪製註釋。下面是我用來畫星的方法。drawRect - Draw Star
-(void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGFloat xCenter = rect.size.width/2;
CGFloat yCenter = rect.size.height/2;
float width;
if(rect.size.width > rect.size.height) {
width = rect.size.height;
} else {
width = rect.size.width;
}
double r = width/2.0;
float flip = -1.0;
double theta = 2.0 * M_PI * (2.0/5.0); // 144 degrees
CGContextMoveToPoint(context, xCenter, r*flip+yCenter);
for (NSUInteger k=1; k<5; k++)
{
float x = r * sin(k * theta);
float y = r * cos(k * theta);
CGContextAddLineToPoint(context, x+xCenter, y*flip+yCenter);
}
CGContextSetStrokeColorWithColor(context, self.color.CGColor);
CGContextClosePath(context);
CGContextStrokePath(context);
}
我想只有明星的邊界刪除其他內部線是否有任何方法來實現這一目標? (除了使用moveToPoint和addLine方法)
由於你知道明星的界限在哪裏,我能想到的只是清除它內部的路徑。 – geekchic
例如,你會計算其餘5個內點,並使用10個點來製作星形 - 多邊形... – holex
星星在中心包含一個倒五角形。我需要明白它的意思,你的意思是? –