1 -(void)drawInContext:(CGContextRef)context 2 { 3 // Drawing with a white stroke color 4 CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0); 5 // Drawing with a blue fill color 6 CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0); 7 // Draw them with a 2.0 stroke width so they are a bit more visible. 8 CGContextSetLineWidth(context, 2.0); 9 10 CGPoint center; 11 12 // Add a star to the current path 13 center = CGPointMake(90.0, 90.0); 14 CGContextMoveToPoint(context, center.x, center.y + 60.0); 15 for(int i = 1; i < 5; ++i) 16 { 17 CGFloat x = 60.0 * sinf(i * 4.0 * M_PI / 5.0); 18 CGFloat y = 60.0 * cosf(i * 4.0 * M_PI / 5.0); 19 CGContextAddLineToPoint(context, center.x + x, center.y + y); 20 } 21 // And close the subpath. 22 CGContextClosePath(context); 23 24 // Now add the hexagon to the current path 25 center = CGPointMake(210.0, 90.0); 26 CGContextMoveToPoint(context, center.x, center.y + 60.0); 27 for(int i = 1; i < 6; ++i) 28 { 29 CGFloat x = 60.0 * sinf(i * 2.0 * M_PI / 6.0); 30 CGFloat y = 60.0 * cosf(i * 2.0 * M_PI / 6.0); 31 CGContextAddLineToPoint(context, center.x + x, center.y + y); 32 } 33 // And close the subpath. 34 CGContextClosePath(context); 35 36 // Now draw the star & hexagon with the current drawing mode. 37 CGContextDrawPath(context, drawingMode); 38 }
                    
                
                
            
        
浙公网安备 33010602011771号