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:
But the result I obtain is the following:
Do you have any idea of why bezier path seems not to be applied in the right way?