Reputation: 779
I am new to iOS and I stucked in this issue. I am creating a custom cell like this
I have taken a rectangular view(on left) inside main view. Here is the code for setting a corner radius of both views.
_viewBG.layer.cornerRadius = 10.0;
_viewBG.layer.shadowOpacity = 0.5;
_viewBG.layer.shadowOffset = CGSizeMake(-1, 1);
_viewBG.layer.borderWidth = 0.5;
_viewBG.layer.borderColor = [[UIColor lightGrayColor] CGColor];
UIBezierPath *maskPath = [UIBezierPath
bezierPathWithRoundedRect:self.viewLeft.bounds
byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft)
cornerRadii:CGSizeMake(10, 10)
];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.viewLeft.layer.mask = maskLayer;
But I am getting this output..
So I want to set the corner radius of red color uiview as per the main view... Any idea would be appreciated. Can you help?
Upvotes: 2
Views: 672
Reputation: 528
steps:
make a main wrapper view which holds your left and right view.. set its background color to clear color..
inside main wrapper view add another view and give it corner radius as desired and mask to bound true
inside this subview made in step 2 add your red and another view with property clip to bounds true
Upvotes: 5
Reputation: 8914
Just set clipToBounds = true
of cell.
in your case it will be _viewBG.clipToBounds = true
To make shadow visible use _viewBG.layer.maskToBounds = false
Upvotes: 0