UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_baseView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(5, 5)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init]; //設置大小 maskLayer.frame = _baseView.bounds; //設置圖形樣子 maskLayer.path = maskPath.CGPath; _baseView.layer.mask = maskLayer;
注意:若是在tableVIewCell的- (void)awakeFromNib {}方法中是要給frame,由於這個方法只加載xib本來的尺寸,致使佈局會有問題佈局