我CAGradientLayer
用 a掩盖 aCAShapeLayer
为了生成位于我表中某些行内的书签。
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddLines(path,
NULL,
(CGPoint[]){
CGPointMake(8, 0),
CGPointMake(22, 0),
CGPointMake(22, 22),
CGPointMake(15, 16),
CGPointMake(8, 22)
},
5);
CGPathCloseSubpath(path);
CAShapeLayer *mask = [CAShapeLayer layer];
mask.fillColor = [UIColor redColor].CGColor;
mask.bounds = CGRectMake(0, 0, 30, 30);
mask.path = path;
mask.anchorPoint = CGPointMake(0, 0);
CGPathRelease(path);
CAGradientLayer *favoriteBadge = [CAGradientLayer layer];
favoriteBadge.colors =
@[(id)[UIColor colorWithRed:.97f green:0.5f blue:0.1f alpha:1.f].CGColor, // orange
(id)[UIColor colorWithRed:1.f green:.8f blue:0.f alpha:1.f].CGColor]; // yellow
favoriteBadge.locations = @[@0.0, @1.0];
favoriteBadge.bounds = CGRectMake(0, 0, 30, 30);
favoriteBadge.anchorPoint = CGPointMake(1, 0);
favoriteBadge.position = CGPointMake(self.bounds.size.width, 0);
favoriteBadge.mask = mask;
// FIXME: This shadow is not being applied
favoriteBadge.shadowColor = [UIColor colorWithRed:.97f green:0.5f blue:0.1f alpha:1.f].CGColor;
favoriteBadge.shadowOpacity = 1.f;
这看起来太平了,所以我想在形状本身周围加上一个阴影来完成这个。我试过在图层上启用阴影,但似乎没有应用。我假设它被应用于不在形状内部的区域。如何为形状本身添加阴影?
我可以复制图层,将其变暗并将其位置偏移几个像素,但是当 CoreAnimation 可能对我来说更有效时,这感觉很浪费。