I am using the following code, and I get an extra stroke line at the left top side in chat bubble. Please check this image for reference:
UIRectCorner corners;
if (type == BubbleTypeSomeoneElse)
{
self.bubbleImage.image = nil;
corners = UIRectCornerBottomRight|UIRectCornerTopRight|UIRectCornerTopLeft;
}
else {
self.bubbleImage.image = nil;
corners = UIRectCornerBottomLeft|UIRectCornerTopRight|UIRectCornerTopLeft;
}
// space between each bubble
self.bubbleImage.frame = CGRectMake(x, y, width + self.data.insets.left + self.data.insets.right, height + self.data.insets.top-10 + self.data.insets.bottom);
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bubbleImage.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(7, 7)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bubbleImage.bounds;
maskLayer.path = path.CGPath;
CAShapeLayer *borderLayer = [[CAShapeLayer alloc] init];
borderLayer.frame = self.bubbleImage.bounds;
borderLayer.path = path.CGPath;
borderLayer.lineWidth = 1.0f;
borderLayer.strokeColor = [UIColor blackColor].CGColor;
borderLayer.fillColor = [UIColor clearColor].CGColor;
[self.bubbleImage.layer addSublayer:borderLayer];
Please let me know what I am doing wrong in the above code, if need anything more from my code comment down I will provide as soon as possible.
Thanks in advance!!
Based on the code you have shown, there's no problem at all:
Therefore the problem is due to code you have not shown. But what that code is, is impossible to say, because, uh, you have not shown that code.
At a guess, however, I would suggest you consider this: Your code shows that you are making the image view's image nil
each time your code runs. That's good. But your code does not remove the previous existing layer
which you added the previous time this code ran. Therefore I'm betting that what you are seeing is left over from the previous existing layer
which you forgot to remove.
Indeed, if this code runs multiple times there is a great danger of piling up sublayers on top of one another.