利用图层的mask属性裁剪图形
2016-06-14 16:54 樊小志 阅读(541) 评论(0) 编辑 收藏 举报需求如上图。
代码如下
//充值 UIButton *rechargeButton = [[UIButton alloc] initWithFrame:CGRectMake(20, 10, 80, 30)]; [rechargeButton setTitle:@"充值" forState:UIControlStateNormal]; [rechargeButton.titleLabel setFont:[UIFont systemFontOfSize:13]]; rechargeButton.backgroundColor = rgb(11, 157, 224); [bottomView addSubview:rechargeButton]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; CGRect rect = rechargeButton.bounds; CGSize radii = CGSizeMake(15, 15); UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerBottomLeft; UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corners cornerRadii:radii]; maskLayer.path = path.CGPath; rechargeButton.layer.mask = maskLayer;
这样我们就可以根据路径,来裁剪到我们想要的形状。
//写下自己想写的,如果有什么错误,还请大家帮我指出来,谢谢。