我正在使用以下代码绘制多边形。我得到的图像如下:
我用来绘制正方形的代码如下:
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);
在所有角的两条线的交界处都有一个白点。有什么办法可以避免有这个点吗?
更新 1:
我知道以下解决方案:根据线宽,可以更改线的起点并实现我的期望。但是还有其他解决办法吗?
更新 2:
我正在使用下面的代码绘制多边形
每当我将 lineWidth 设置为 1 或小于 1 时,都会发生同样的问题。如果我将它设置为 2 或更高,则不会出现问题。
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, topLeftBoxBorderColor.CGColor);
CGRect rectangle = CGRectMake(originXOfSubviews,originYOfSubviews,widthOfBox,heightOfBox);
CGContextAddRect(context, rectangle);
CGContextStrokePath(context);
最佳答案
它是两条线(水平线和垂直线)的交点。
你可以做的是让这条线比你现在使用的总长度小几个像素/点。它不会相交,也不会出现点。
编辑:
或者你可以画正方形,而不是画线
- (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);
}
关于ios - 为什么在iOS中使用核心图形绘制的线的连接处会出现一个点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13680607/