美文网首页
iOS 绘制像邮票边缘一样的凹巢

iOS 绘制像邮票边缘一样的凹巢

作者: 菊上一枝梅 | 来源:发表于2018-07-18 09:56 被阅读19次
- (void)loadView {
    [super loadView];
    
    CGFloat width = 200;
    CGFloat height = 400;
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 150, width, height)];
    view.backgroundColor = [UIColor redColor];
    [self.view addSubview:view];
    
    CGFloat radius = 10; // 半径
    
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(0, 0)];
    [path addLineToPoint:CGPointMake(width, 0)];
    [path addLineToPoint:CGPointMake(width, height / 2 - radius)];
    [path addArcWithCenter:CGPointMake(width, height / 2) radius:radius startAngle:1.5 * M_PI endAngle:0.5 * M_PI clockwise:NO]; // 右面凹巢
    [path addLineToPoint:CGPointMake(width, height)];
    [path addLineToPoint:CGPointMake(0, height)];
    [path addLineToPoint:CGPointMake(0, height / 2 + radius)];
    [path addArcWithCenter:CGPointMake(0, height / 2) radius:radius startAngle:0.5 * M_PI endAngle:1.5 * M_PI clockwise:NO]; // 左面凹巢
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = view.bounds;
    maskLayer.path = path.CGPath;
    view.layer.mask = maskLayer;
    
    /**
     圆上方:1.5π
     圆右方:2π
     圆下方:0.5π
     圆左方:π
     */
}
image

相关文章

网友评论

      本文标题:iOS 绘制像邮票边缘一样的凹巢

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