Is there a way to set cornerRadius
for only top-left and top-right corner of a UIView
?
I tried the following, but it end up not seeing the view anymore.
UIView *view = [[UIView alloc] initWithFrame:frame];
CALayer *layer = [CALayer layer];
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRoundedRect:frame byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(3.0, 3.0)];
layer.shadowPath = shadowPath.CGPath;
view.layer.mask = layer;
The easiest way would be to make a mask with a rounded corner layer.
And don't forget to:
Swift code example here: https://stackoverflow.com/a/35621736/308315
Not directly. You will have to:
CAShapeLayer
path
to be aCGPathRef
based onview.bounds
but with only two rounded corners (probably by using+[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]
)view.layer.mask
to be theCAShapeLayer
Here is a short method implemented like this:
iOS 11 , Swift 4
And you can try this code:
And you can using this in table view cell.
A lovely extension to reuse Yunus Nedim Mehel solution
Swift 2.3
Usage