CoreGraphics - 两条四边形形状路径之间可见的间隙

时间:2016-08-29 12:22:22

标签: ios objective-c core-graphics

我使用CoreGraphics绘制了两条四边形(4边)形状的路径。共有6个点,path1使用前4个点,path2使用最后4个点,因此共享2个点。

代码如下

std::function<double  (const double)> plus (const double a) {
    return [a] (const double b) -> double {
        return a+b;
    };
}

auto plus5 = plus(5);
cout << plus5.a << endl;

输出图像是

enter image description here

但是在屏幕上,连接边缘出现奇怪的白线。我想删除白线。

任何人都可以帮助如何避免这条白线?

1 个答案:

答案 0 :(得分:2)

首先将两个路径添加到上下文中,然后填充它。

- (void)drawRect:(CGRect)rect {

    CGPoint topLeft = CGPointMake(121, 116);
    CGPoint topRight = CGPointMake(221, 216);

    CGPoint middleLeft = CGPointMake(121, 180);
    CGPoint middleRight = CGPointMake(221, 280);

    CGPoint bottomLeft = CGPointMake(121, 244);
    CGPoint bottomRight = CGPointMake(221, 344);

    CGMutablePathRef subpath1 = CGPathCreateMutable();
    CGPathMoveToPoint(subpath1, NULL, topLeft.x, topLeft.y);
    CGPathAddLineToPoint(subpath1, NULL, topRight.x, topRight.y);
    CGPathAddLineToPoint(subpath1, NULL, middleRight.x, middleRight.y);
    CGPathAddLineToPoint(subpath1, NULL, middleLeft.x, middleLeft.y);
    CGPathAddLineToPoint(subpath1, NULL, topLeft.x, topLeft.y);

    CGMutablePathRef subpath2 = CGPathCreateMutable();
    CGPathMoveToPoint(subpath2, NULL, middleLeft.x, middleLeft.y);
    CGPathAddLineToPoint(subpath2, NULL, middleRight.x, middleRight.y);
    CGPathAddLineToPoint(subpath2, NULL, bottomRight.x, bottomRight.y);
    CGPathAddLineToPoint(subpath2, NULL, bottomLeft.x, bottomLeft.y);
    CGPathAddLineToPoint(subpath2, NULL, middleLeft.x, middleLeft.y);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [UIColor colorWithRed:0.19 green:0.42 blue:0.09 alpha:1.0].CGColor);
    CGContextSetBlendMode(context, kCGBlendModeMultiply);
    CGContextSetAlpha(context, 1.0);

    // Changes start here...
    CGContextAddPath(context, subpath1);
    CGContextAddPath(context, subpath2);
    CGContextFillPath(context);
}