我正在嘗試爲一個圓角和筆畫/邊框創建一個標籤(或其他任何視圖)。我可以使用下面的代碼實現了前者:iOS中的行程蒙面CALayer
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」添加爲子視圖來實現它的工作。非常感謝:) –
StrokeLayer覆蓋標籤,所以我補充說,以解決這個問題 'shape.fillColor = [UIColor clearColor] .CGColor' –