半圆往view中间凹陷

  UIView *tgBlackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];

        tgBlackView.backgroundColor = tgrgba(34, 34, 34, 1);

        tgBlackView.alpha = 0.58;

        [self addSubview:tgBlackView];

        

        int tgLogImageViewW = 110;

        int tgWhiteViewH = 250;

        UIView *tgWhiteView = [[UIView alloc]initWithFrame:CGRectMake(20, kScreenHeight-kTabBarBottomHeight-tgWhiteViewH, kScreenWidth-40, tgWhiteViewH)];

        tgWhiteView.backgroundColor = [UIColor clearColor];

        tgWhiteView.layer.cornerRadius = 17;

        tgWhiteView.layer.masksToBounds = YES;

        [self addSubview:tgWhiteView];

        

        //圆图片

        UIImageView *tgLogImageView = [[UIImageView alloc]initWithFrame:CGRectMake((kScreenWidth-tgLogImageViewW)/2, tgWhiteView.frame.origin.y-tgLogImageViewW/2, tgLogImageViewW, tgLogImageViewW)];

        tgLogImageView.image = [UIImage imageNamed:@"fresh_update"];

        tgLogImageView.backgroundColor = tgrgba(65, 171, 166, 1);

        tgLogImageView.layer.cornerRadius = tgLogImageView.frame.size.height/2;

        tgLogImageView.layer.masksToBounds = YES;

        tgLogImageView.contentMode = UIViewContentModeScaleAspectFill;

        [self addSubview:tgLogImageView];

        

        

        // 创建一个CAShapeLayer

        CAShapeLayer *shapeLayer = [CAShapeLayer layer];

        UIBezierPath *path = [UIBezierPath bezierPath];

        CGFloat radius = tgLogImageViewW/2+8; // 半径

        [path moveToPoint:CGPointMake(0, 0)];

        [path addLineToPoint:CGPointMake(0, tgWhiteView.bounds.size.height)];

        [path addLineToPoint:CGPointMake(tgWhiteView.bounds.size.width, tgWhiteView.bounds.size.height)];

        [path addLineToPoint:CGPointMake(tgWhiteView.bounds.size.width, 0)];

        [path addArcWithCenter:CGPointMake(tgWhiteView.bounds.size.width / 2, 0)

                        radius:radius

                    startAngle:0

                      endAngle:M_PI

                     clockwise:YES];

        [path addLineToPoint:CGPointMake(0, 0)];

        [path closePath];

        // 设置CAShapeLayer的路径

        shapeLayer.path = path.CGPath;

        // 设置填充颜色为透明

        shapeLayer.fillColor = [UIColor whiteColor].CGColor;

        // 添加CAShapeLayer到白色的UIView的layer

        [tgWhiteView.layer addSublayer:shapeLayer];

你可能感兴趣的:(ios)