为什么在iOS中使用核心图形绘制的线的连接处会出现点?
我正在使用下面的代码绘制一个多边形。我得到的图像如下:为什么在iOS中使用核心图形绘制的线的连接处会出现点?,ios,core-graphics,Ios,Core Graphics,我正在使用下面的代码绘制一个多边形。我得到的图像如下: CGContextRef currentContext = UIGraphicsGetCurrentContext(); [topLeftBoxBorderColor set]; CGContextSetLineWidth(currentContext, 1.0f); CGContextSetLineJoin(currentContext,kCGLineJoinMiter); CGContextMoveToPoint(currentCont
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);
我用于绘制正方形的代码如下:
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:
我正在使用下面的代码来绘制多边形
当我将线宽设置为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);
}
你使用透明的颜色吗?我没有看到额外的白点,我看到交叉点是重叠的,这会在某种程度上涉及透明效果时产生这种效果。在那个位置有nö附加点,有一个点的颜色错误。谢谢你的更正。这是一种重叠,但这种重叠只有在某种程度上涉及透明度时才可见。(全白就是全白)我不希望他们被填满。