2

I have to add a border with a wooden texture to a UIView. In order to do this I thought the following solution:

  • I have the original UIView (say uiViewA)
  • I create another UIView (say uiViewB) with the same size of the first one
  • I create a bezier path with a 8px width
  • Once created the path I apply this to uiViewB
  • I add uiViewB to uiViewA's subviews

The code to apply the bezier path is the following:

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];

I would like to obtain the following result:

enter image description here

But the result I obtain is the following:

enter image description here

Do you have any idea of why bezier path seems not to be applied in the right way?

4

1 回答 1

2

从那里的代码看来,您正在使用用作蒙版的形状图层的默认填充和描边,因此路径被填充,您得到了您所看到的结果。

您要做的是设置清晰的填充颜色并设置一些随机的不透明笔触颜色。然后,您必须设置适当的线宽、线帽、线圆等来配置笔划的外观。

于 2013-10-03T09:17:37.220 回答