在实现周围的边框这块,想的是生成切圆角的 shape layer 并带有边框颜色 然后用layer.mask的属性实现
CornerRadii cm = CornerRadiiMake(0, 0, 10, 10);
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
CGPathRef path = CYPathCreateWithRoundedRect(self.chooseCountsView.bounds,cm);
shapeLayer.lineWidth = 1.f;
shapeLayer.fillColor = [UIColor clearColor].CGColor;
//边框颜色
shapeLayer.strokeColor = [UIColor redColor].CGColor;
shapeLayer.frame = self.chooseCountsView.bounds;
shapeLayer.path = path;
CGPathRelease(path);
self.chooseCountsView.layer.mask = shapeLayer;
但是发现并不起效果
各种搜索之后发现这种场景需要将 shapeLayer add layer到对应的目标上 mask 是带不了边框颜色的
CornerRadii cm = CornerRadiiMake(0, 0, 10, 10);
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
CGPathRef path = CYPathCreateWithRoundedRect(self.chooseCountsView.bounds,cm);
shapeLayer.lineWidth = 1.f;
shapeLayer.fillColor = [UIColor clearColor].CGColor;
//边框颜色
shapeLayer.strokeColor = [UIColor redColor].CGColor;
shapeLayer.frame = self.chooseCountsView.bounds;
shapeLayer.path = path;
CGPathRelease(path);
[self.chooseCountsView.layer addSublayer:shapeLayer];
相关 :
https://stackoverflow.com/questions/29203506/the-strokecolor-of-cashapelayer-not-work
You are adding your shape layer as a mask layer. That allows the brightness of the mask layer's pixels to determine the opacity of the layer it's masking. It sounds like that's not what you want.
Instead, add your shape layer as a sublayer of your view's layer. Change
self.layer.mask = shapeLayer;
to
[self.layer addSublayer: shapeLayer];