UIView に木製のテクスチャの境界線を追加する必要があります。これを行うために、次の解決策を考えました。
- 私は元のUIViewを持っています(uiViewAと言います)
- 最初のUIViewと同じサイズの別のUIView(uiViewBなど)を作成します
- 幅 8px のベジエ パスを作成します
- パスを作成したら、これを uiViewB に適用します
- uiViewA のサブビューに uiViewB を追加します
ベジエ パスを適用するコードは次のとおりです。
UIView* uiViewB = [[UIView alloc] initWithFrame:uiViewA.bounds];
UIImage* wood = [UIImage imageNamed:@"texture_wood"];
[uiViewB setBackgroundColor:[UIColor colorWithPatternImage:wood]];
// creation of the bezier path
UIBezierPath* borderPath = ... ;
[borderPath setLineWidth:8.0];
[borderPath moveToPoint:CGPointMake(0.0, 0.0)];
borderPath addLineToPoint:...
borderPath addArcWithCenter:...
borderPath addLineToPoint:...
borderPath addArcWithCenter:...
borderPath addLineToPoint:...
CAShapeLayer* borderMaskLayer = [CAShapeLayer layer];
[borderMaskLayer setFrame:uiViewA.bounds];
borderMaskLayer.path = [borderPath CGPath];
uiViewB.layer.mask = borderMaskLayer;
[uiViewB.layer setMasksToBounds:YES];
次の結果を得たいと思います。
しかし、私が得た結果は次のとおりです。
ベジェ パスが正しい方法で適用されていないように見える理由について何か考えはありますか?