2016-07-13 27 views

Antwort

2

diesen Weg versuchen:

//// Star Drawing 
UIBezierPath* starPath = [UIBezierPath bezierPath]; 
[starPath moveToPoint: CGPointMake(45.25, 0)]; 
[starPath addLineToPoint: CGPointMake(61.13, 23)]; 
[starPath addLineToPoint: CGPointMake(88.29, 30.75)]; 
[starPath addLineToPoint: CGPointMake(70.95, 52.71)]; 
[starPath addLineToPoint: CGPointMake(71.85, 80.5)]; 
[starPath addLineToPoint: CGPointMake(45.25, 71.07)]; 
[starPath addLineToPoint: CGPointMake(18.65, 80.5)]; 
[starPath addLineToPoint: CGPointMake(19.55, 52.71)]; 
[starPath addLineToPoint: CGPointMake(2.21, 30.75)]; 
[starPath addLineToPoint: CGPointMake(29.37, 23)]; 
[starPath closePath]; 
[UIColor.redColor setStroke]; 
starPath.lineWidth = 1; 
[starPath stroke]; 

Sie Paint Code App verwenden können Form für iOS und OS X zu zeichnen. Dies ist einfach zu bedienen und sehr hilfreiche App.

Glückliche Kodierung.

+0

Danke für Ihre Hilfe. Es funktioniert. –

+0

Kannst du es bitte ein bisschen groß machen? –

+0

@AtplMohali, Bitte aktualisierten Code nehmen. –

1

Ich denke, das ist das, was Sie suchen:

func starPathInRect(rect: CGRect) -> UIBezierPath { 
    let path = UIBezierPath() 

    let starExtrusion:CGFloat = 30.0 

    let center = CGPointMake(rect.width/2.0, rect.height/2.0) 

    let pointsOnStar = 5 + arc4random() % 10 

    var angle:CGFloat = -CGFloat(M_PI/2.0) 
    let angleIncrement = CGFloat(M_PI * 2.0/Double(pointsOnStar)) 
    let radius = rect.width/2.0 

    var firstPoint = true 

    for i in 1...pointsOnStar { 

     let point = pointFrom(angle, radius: radius, offset: center) 
     let nextPoint = pointFrom(angle + angleIncrement, radius: radius, offset: center) 
     let midPoint = pointFrom(angle + angleIncrement/2.0, radius: starExtrusion, offset: center) 

     if firstPoint { 
      firstPoint = false 
      path.moveToPoint(point) 
     } 

     path.addLineToPoint(midPoint) 
     path.addLineToPoint(nextPoint) 

     angle += angleIncrement 
    } 

    path.closePath() 

    return path 
} 

Über diese Funktion können Sie entscheiden, wie viele Punkte Sie in Ihren Stars wollen ..

prüfen diese link für mehr detailed description .

Hoffe, dass dies hilft. :) Lass mich für jede Anfrage wissen .. !!!