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];//创建shapelayer
masklayer.frame = button.bounds;
masklayer.path = path.CGPath;//设置路径
button.layer.mask = masklayer;
注意 Masonry布局时,要在Masonry布局后调用
[self layoutIfNeeded];
网友评论