我正在尝试创建一个带有一个圆角和描边/边框的标签(或者其他视图)。我可以使用以下代码实现圆角效果:
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.label.bounds
byRoundingCorners:UIRectCornerBottomRight
cornerRadii:CGSizeMake(16.0f, 16.0f)];
CAShapeLayer *shape = [CAShapeLayer layer];
shape.frame = self.label.bounds;
shape.path = maskPath.CGPath;
self.label.layer.mask = shape;
对于圆角来说,这很好用,但是使用下面的代码不能按照我想要的方式应用描边。相反,它产生了一个黑色(或者与self.label
的backgroundColor
设置相同的颜色)的方形边框。
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.label.bounds
byRoundingCorners:UIRectCornerBottomRight
cornerRadii:CGSizeMake(16.0f, 16.0f)];
CAShapeLayer *shape = [CAShapeLayer layer];
shape.frame = self.label.bounds;
shape.path = maskPath.CGPath;
// Add stroke
shape.borderWidth = 1.0f;
shape.borderColor = [UIColor whiteColor].CGColor;
self.label.backgroundColor = [UIColor blackColor];
self.label.layer.mask = shape;
你有什么建议,我怎样可以应用一个随着被遮罩路径移动的任意颜色描边?
UIView
上,并将UILabel
添加为其子视图。非常感谢 :) - Steve Wilfordshape.fillColor = [UIColor clearColor].CGColor
。 - name-it