使用NSBezierPath
仅使用外表面绘制星形。下面的代码是与所有线相交的绘制星。
- (NSBezierPath *) getPathForStar{
CGRect rect =self.frame;
NSBezierPath * path = [NSBezierPath bezierPath];
[path setLineWidth: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
[path moveToPoint:CGPointMake(xCenter, r*flip+yCenter)];
for (NSUInteger k=1; k<5; k++)
{
float x = r * sin(k * theta);
float y = r * cos(k * theta);
[path lineToPoint:CGPointMake( x+xCenter, y*flip+yCenter)];
}
return path;
}
我想只绘制明星的边界。感谢。