Sto mascherando un CAGradientLayer
con un CAShapeLayer
per generare un segnalibro che si trova all'interno di determinate righe nella mia tabella.Aggiungi ombra attorno alla regione mascherata di un CALayer
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;
Questo sembra troppo piatta, quindi voglio finire questa via con un'ombra intorno alla forma stessa. Ho provato a abilitare l'ombra sul livello, ma non sembra essere applicato. Presumo che venga applicato nell'area che non si trova all'interno della forma. Come posso aggiungere un'ombra alla forma stessa?
Potrei copiare il livello, scurirlo e spostarlo di pochi pixel, ma è inutile quando CoreAnimation può probabilmente farlo in modo più efficiente.
+1 ben chiese + id piacerebbe sapere troppo: DI spostare sempre l'immagine e disegnare roba me stesso .. –