I need some common function or library to create different polygon shapes (pentagon, Hexagon) with straight lines and curved corners from a list of some dynamic CGPoints in array using a Bezier path. The points should be corners of polygon shape
1 Answers
I'm afraid I don't program in Objective-C or have ever used anything using Bezier paths. From a quick google search I managed to find : https://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/BezierPaths/BezierPaths.html
Again, I haven't programmed in Objective-C so this may be completely wrong. However, summarizing that article:
// Create a Bezier path
UIBezierPath *aPath = [UIBezierPath bezierPath];
// Set the starting point of the shape.
[aPath moveToPoint:CGPointMake(100.0, 0.0)];
// Draw the lines.
[aPath addLineToPoint:CGPointMake(200.0, 40.0)]; // 200 = x, 40 = y
[aPath addLineToPoint:CGPointMake(160, 140)];
[aPath addLineToPoint:CGPointMake(40.0, 140)];
[aPath addLineToPoint:CGPointMake(0.0, 40.0)];
// Stop defining the points of the shape to draw
[aPath closePath];
From what it looks. You declare a point using:
[aPath addLineToPoint:CGPointMake(160, 140)];
Replace 160 with the starting x, replace 140 with the starting y. You then add more of those aPath's and they will join up with the coordinates of the last point. The last point defined will link up with the first point defined.
For adding curved edges you may want to check out Polygon with rounded corners using UIBezierPath. Duncan C (question with 6 votes as of currently) explains it. I'm not sure if it's helpful or correct because I have no experience in Objective-C.