CGRect rect = CGRectMake(0, 0, 100, 50);
CGSize radio = CGSizeMake(5, 5);//圓角尺寸
UIRectCorner corner = UIRectCornerTopLeft|UIRectCornerTopRight;//這只圓角位置(自定義)
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corner cornerRadii:radio];
CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];//創(chuàng)建shapelayer
masklayer.frame = button.bounds;
masklayer.path = path.CGPath;//設(shè)置路徑
button.layer.mask = masklayer;
注意 Masonry布局時(shí),要在Masonry布局后調(diào)用
[self layoutIfNeeded];