Search code examples
iosobjective-cswiftdrawinguibezierpath

How to make star shape with bezier path in ios?


I am working with Bezier path and making simple shapes with it. What is the process for making a star shape using Bezier paths?


Solution

  • Try this path:

    //// 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];
    

    You can use Paint Code app to draw shape for iOS and OSX. This is easy to use and very helpful app.

    Happy Coding.