iOS 添加内阴影

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 添加内阴影)