iHarshil
iHarshil

Reputation: 779

How to set corner radius of a view inside a view in tableview cell?

I am new to iOS and I stucked in this issue. I am creating a custom cell like thisUITableviewcell

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

Answers (2)

Ashwin Shrestha
Ashwin Shrestha

Reputation: 528

steps:

  1. make a main wrapper view which holds your left and right view.. set its background color to clear color..

  2. inside main wrapper view add another view and give it corner radius as desired and mask to bound true

  3. inside this subview made in step 2 add your red and another view with property clip to bounds true

  4. now in main wrapperview give your shadow and mask to bound set false

Upvotes: 5

Mahendra
Mahendra

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

Related Questions