Reputation: 12221
I am using the below code to draw a polygon. The image I get is below:
The code I am using for drawing the square is below:
CGContextRef currentContext = UIGraphicsGetCurrentContext();
[topLeftBoxBorderColor set];
CGContextSetLineWidth(currentContext, 1.0f);
CGContextSetLineJoin(currentContext,kCGLineJoinMiter);
CGContextMoveToPoint(currentContext, originXOfSubviews, originYOfSubviews);
CGContextAddLineToPoint(currentContext, originXOfSubviews+widthOfBox, originYOfSubviews);
CGContextAddLineToPoint(currentContext, originXOfSubviews+widthOfBox, originYOfSubviews+heightOfBox);
CGContextAddLineToPoint(currentContext, originXOfSubviews, originYOfSubviews+heightOfBox);
CGContextAddLineToPoint(currentContext, originXOfSubviews, originYOfSubviews);
CGContextStrokePath(currentContext);
There is a white dot at the junction of two lines in all corners. Is there any way to avoid having this dot?
UPDATE 1:
I know the below solution: Based on the line width the , starting point of the line can be changed and achieved what I expect. But is there any other solution?
UPDATE 2:
I am using the below code to draw the polygon
When ever I set the lineWidth to 1 or less than that, the same problem happens. If I set it to 2 or above the problem does not arise.
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, topLeftBoxBorderColor.CGColor);
CGRect rectangle = CGRectMake(originXOfSubviews,originYOfSubviews,widthOfBox,heightOfBox);
CGContextAddRect(context, rectangle);
CGContextStrokePath(context);
Upvotes: 0
Views: 194
Reputation: 46543
It is the intersection of both the lines (Horizontal and Vertical).
What you can do is make this line few pixels/points lesser than the total lenght that you are using now. It wont intersect and no dot will come.
EDIT:
Or you can draw square,instead of drawling lines
- (void)drawSquare:(CGRect)rect{
//Get the CGContext from this view
CGContextRef context = UIGraphicsGetCurrentContext();
//Draw a rectangle
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
//Define a rectangle
CGContextAddRect(context, rect);
//Draw it
CGContextFillPath(context);
}
Upvotes: 2