I propose a different approach. Download the image with rounded top corners and set it as content CALayer. Set this layer as the mask of your layer. Update the size of the mask layer in layoutSubivewsthis view or viewDidLayoutSubviewsthis view controller.
contenst
CALayer *maskLayer = [[CALayer alloc] init];
UIImage *maskImage = [UIImage imageNamed:@"mask_image.png" inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
maskLayer.contents = (__bridge id _Nullable)(maskImage.CGImage);
mainLayer.mask = maskLayer
[EDIT]
CAShapeLayer , , , . UITableViewCell, layoutSubviews. (MyTableCell ):
@interface MyTableCell ()
@property (nonatomic, strong) CAShapeLayer *maskLayer;
@end
@implementation MyTableCell
- (void)awakeFromNib
{
self.maskLayer = [[CAShapeLayer alloc] init];
self.layer.mask = self.maskLayer;
}
- (void)layoutSubviews
{
[super layoutSubviews];
self.maskLayer.path = [self maskPath].CGPath;
}
- (UIBezierPath *)maskPath
{
return [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners: (UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(10.0, 10.0)];
}
@end