- (void)layoutSublayersOfLayer:(CALayer *)layer {
//使用masonry加
[_chatBackView layoutIfNeeded];
//防止复用重复添加layer
for (CALayer *layer in _chatBackView.layer.sublayers) {
if ([layer.name isEqualToString:@"lit"]) {
[layer removeFromSuperlayer];
}
}
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_chatBackView.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer = [CAShapeLayer layer];
shapeLayer.path = maskPath.CGPath;
_chatBackView.layer.mask = shapeLayer;
CAShapeLayer *borderLayer=[CAShapeLayer layer];
borderLayer.path = maskPath.CGPath;
borderLayer.fillColor = [UIColor clearColor].CGColor;
borderLayer.strokeColor = _borderColor.CGColor;
borderLayer.lineWidth = 2;
borderLayer.frame = _chatBackView.bounds;
[borderLayer setName:@"lit"];
[_chatBackView.layer addSublayer:borderLayer];
}
网友评论