objective c - Masking a sublayer gradient to CAShapeLayer -
i have cashapelayer
bezierpathwithovalinrect
. want make gradient layer fill circle, @ moment fills whole frame.
how do this?
cashapelayer *layerinsides = [cashapelayer layer]; layerinsides.path = [uibezierpath bezierpathwithovalinrect:rectfrom(frameinsides)].cgpath; cagradientlayer *gradientlayer = [cagradientlayer layer]; gradientlayer.frame = layerinsides.frame; gradientlayer.colors = @[(id)[uicolor colorwithred:1 green:0 blue:0 alpha:1].cgcolor, (id)[uicolor colorwithred:0 green:0 blue:0 alpha:1].cgcolor]; gradientlayer.locations = @[@0.0, @1]; gradientlayer.cornerradius = self.layer.cornerradius; [layerinsides addsublayer:gradientlayer];
instead of adding content shape sublayer need set cashapelayer mask
colored layer:
gradientlayer.mask = layerinsides;
Comments
Post a Comment