Reputation: 2217
I have drawn two Quadrilaterals(4 sides) shaped paths using CoreGraphics. There are 6 points totally, path1 uses the first 4 points and path2 uses the last 4 points thus both sharing 2 points.
The code is follows
- (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);
CGContextAddPath(context, subpath1);
CGContextFillPath(context);
CGContextAddPath(context, subpath2);
CGContextFillPath(context);
}
The output image is
But in the screen there is a odd white line appears in the joining edge. I want to remove the white line.
Can anyone help how to avoid this white line?
Upvotes: 1
Views: 69
Reputation: 751
Add both paths to the context first and then fill it.
- (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);
}
Upvotes: 2