美文网首页
iOS 添加内阴影

iOS 添加内阴影

作者: Farmers | 来源:发表于2016-11-17 12:01 被阅读912次

    CAShapeLayer* shadowLayer = [CAShapeLayerlayer];

    [shadowLayersetFrame:_imageView.bounds];

    // Standard shadow stuff

    [shadowLayersetShadowColor:[[UIColorcolorWithWhite:0alpha:0.8]CGColor]];

    [shadowLayersetShadowOffset:CGSizeMake(0.0f,0.0f)];

    [shadowLayersetShadowOpacity:1.0f];

    // Causes the inner region in this example to NOT be filled.

    [shadowLayersetFillRule:kCAFillRuleEvenOdd];

    // Create the larger rectangle path.

    CGMutablePathRefpath =CGPathCreateMutable();

    CGPathAddRect(path,NULL,CGRectInset(_imageView.bounds, -42, -42));

    // Add the inner path so it's subtracted from the outer path.

    // someInnerPath could be a simple bounds rect, or maybe

    // a rounded one for some extra fanciness.

    CGPathRefsomeInnerPath = [UIBezierPathbezierPathWithRoundedRect:_imageView.boundscornerRadius:10.0f].CGPath;

    CGPathAddPath(path,NULL, someInnerPath);

    CGPathCloseSubpath(path);

    [shadowLayersetPath:path];

    CGPathRelease(path);

    [[_imageViewlayer]addSublayer:shadowLayer];

    CAShapeLayer* maskLayer = [CAShapeLayerlayer];

    [maskLayersetPath:someInnerPath];

    [shadowLayersetMask:maskLayer];

    相关文章

      网友评论

          本文标题:iOS 添加内阴影

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