我正在屏蔽CAGradientLayer
和CAShapeLayer
,以便生成位於表格中某些行內的書籤。在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;
這看起來太平坦,所以我想與周圍的形狀本身陰影完成這一關。我已經嘗試在圖層上啓用陰影,但似乎沒有得到應用。我認爲它被應用在不在形狀內的區域。我怎樣才能爲形狀本身添加陰影?
我可以複製圖層,使圖層變暗並將其位置偏移幾個像素,但是當CoreAnimation可能對我更有效時,它會感到浪費。
+1很好地問道+ ID喜歡太瞭解:DI始終將圖像和借鑑的東西自己.. –