12

丸みを帯びた角とストローク/境界線を持つラベル (またはその他のビュー) を作成しようとしています。次のコードを使用して前者を実現できます。

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;

これは丸みを帯びた角にはうまく機能しますが、次のコードを使用すると、思い通りにストロークが適用されません。代わりに、黒 (またはbackgroundColorself.labelが設定されているもの)の正方形の境界線を生成します。

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;

マスクされたパスをたどる任意の色付きのストロークを適用する方法について何か提案はありますか?

4

2 に答える 2