美文网首页
类似二维码扫码中间中空的效果

类似二维码扫码中间中空的效果

作者: 请叫我魔法师 | 来源:发表于2017-05-30 09:24 被阅读0次

二维码扫码的时候,背景是黑色的,中间有个中空的部分。
1.画1条外边框矩形
2.再画一条内边框矩形,设置成反向绘制。
3.两条曲线拼接,设置背景的layey.mask即可。

UIView *bgView = [[UIView alloc] initWithFrame:self.view.bounds];
bgView.backgroundColor = [UIColor blackColor];
bgView.alpha = 0.5;
[self.view addSubview:bgView];
    
UIBezierPath *path1 = [UIBezierPath bezierPathWithRect:self.view.bounds];
UIBezierPath *path2 = [[UIBezierPath bezierPathWithRoundedRect:CGRectMake(50, 100, self.view.frame.size.width-100, 200) cornerRadius:10]
bezierPathByReversingPath];
[path1 appendPath:path2];
    
CAShapeLayer *maskL = [[CAShapeLayer alloc] init];
maskL.path = path1.CGPath;
bgView.layer.mask = maskL;
5923F250-FB78-4B13-BD43-C50ACD4A07E0.png

相关文章

网友评论

      本文标题:类似二维码扫码中间中空的效果

      本文链接:https://www.haomeiwen.com/subject/iszlfxtx.html