I've a table, with one section (which is default behaviour). It has 5 rows by default, and can have rows < 5 or rows > 5 rows based on some user interaction with the app.
I want to make first and last cell to be rounded from top left/ right and bottom left/ right respectively.
I'm able to do it by UIBezierPath
and CAShapeLayer
. But the problem is comes when number of rows will get increase/ decrease. I'm not sure how to reset previously rounded cells and update a new one with particular case?
Another problem occurs when I put table in edit mode, when a delete button will be visible, it'll not show for the first and last cells. Its there, but not visible.
Here's the screenshot from the app.
- The blue border is a table view.
- Table without border looks like this, note rounded corners in first and last row.
- If I wants to delete first and last cell then it'll look like below images,
- For other cells, it'll look like this,
Can any one tell me, what I'm doing wrong here?
Here's my code:
- (void) roundCornersAtTopInView:(UIView *)view withRadius:(float)radius withSize:(CGSize)size {
UIRectCorner corner = (UIRectCornerTopLeft | UIRectCornerTopRight);
UIView *roundedView = view;
CGRect actualRect = CGRectMake(roundedView.frame.origin.x, roundedView.frame.origin.y, size.width, size.height);
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:actualRect byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = actualRect;
maskLayer.path = maskPath.CGPath;
roundedView.layer.mask = maskLayer;
roundedView.layer.masksToBounds = YES;
}
- (void) roundCornersAtBottomInView:(UIView *)view withRadius:(float)radius withSize:(CGSize)size {
UIRectCorner corner = (UIRectCornerBottomLeft | UIRectCornerBottomRight);
UIView *roundedView = view;
CGRect actualRect = CGRectMake(roundedView.frame.origin.x, roundedView.frame.origin.y, size.width, size.height);
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:actualRect byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = actualRect;
maskLayer.path = maskPath.CGPath;
roundedView.layer.mask = maskLayer;
roundedView.layer.masksToBounds = YES;
}