Ios7 CAShapeLayer strokeColor与fillColor混合

Ios7 CAShapeLayer strokeColor与fillColor混合,ios7,quartz-core,cashapelayer,Ios7,Quartz Core,Cashapelayer,我画了一个有边界的六边形视图。我现在面临的问题是,我无法为使用strokeWidth(非borderWidth)制作的边框设置所需的颜色,现在我的图层的strokeColor与图层的填充颜色混合 代码如下: CAShapeLayer *hexagonMask = [CAShapeLayer layer]; CAShapeLayer *hexagonBorder = [CAShapeLayer layer]; hexagonMask.frame=self.layer.bounds; hexagon

我画了一个有边界的六边形视图。我现在面临的问题是,我无法为使用strokeWidth(非borderWidth)制作的边框设置所需的颜色,现在我的图层的strokeColor与图层的填充颜色混合

代码如下:

CAShapeLayer *hexagonMask = [CAShapeLayer layer];
CAShapeLayer *hexagonBorder = [CAShapeLayer layer];
hexagonMask.frame=self.layer.bounds;
hexagonBorder.frame = self.layer.bounds;

UIBezierPath* hexagonPath=[self makeHexagonalMaskPathWithSquareSide:side];     //making hexagon path

hexagonMask.path = hexagonPath.CGPath;                 //setting the mask path for hexagon
hexagonBorder.path = hexagonPath.CGPath;               //setting the maskpath for hexagon border
hexagonBorder.fillColor=[UIColor clearColor].CGColor; //setting by default color

hexagonBorder.lineWidth = self.customBorderWidth; //   setting border width

hexagonBorder.strokeColor = self.customBorderColor.CGColor;  //setting  color for hexagon border 

hexagonBorder.fillColor = self.customFillColor.CGColor;    //setting fill color for hexagon     

有什么解决这个问题的建议吗?

最后我找到了解决这个问题的办法。 我添加了一个CALayer作为子层,填充颜色用于创建一个UIImage,用于设置子层的内容。 下面是将来可能面临此问题的人的代码

CAShapeLayer *hexagonMask = [CAShapeLayer layer];
CAShapeLayer *hexagonBorder = [CAShapeLayer layer];
hexagonMask.frame=self.layer.bounds;
hexagonBorder.frame = self.layer.bounds;

UIBezierPath* hexagonPath=[self makeHexagonalMaskPathWithSquareSide:side];       //making hexagon path

hexagonMask.path = hexagonPath.CGPath;                 //setting the mask path for   hexagon
hexagonBorder.path = hexagonPath.CGPath;               //setting the maskpath for hexagon border
hexagonBorder.fillColor=[UIColor clearColor].CGColor; //setting by default color

hexagonBorder.lineWidth = self.customBorderWidth; //   setting border width

hexagonBorder.strokeColor = self.customBorderColor.CGColor;  //setting  color for hexagon border 


CGFloat coverImageSide=side-(_customBorderWidth);
            CGFloat backgroundLayerXY=_customBorderWidth/2.0;

            UIImage *coverImage=[UIImage ImageWithColor:_customFillColor width:coverImageSide height:coverImageSide];
            UIBezierPath* dpath=[self makeHexagonalMaskPathWithSquareSide:coverImageSide];


            CALayer *backgroundLayer=[CALayer layer];
            backgroundLayer.frame=CGRectMake(backgroundLayerXY, backgroundLayerXY, coverImageSide, coverImageSide);
            CAShapeLayer *backgroundMaskLayer=[CAShapeLayer layer];
            backgroundMaskLayer.path=dpath.CGPath;
            backgroundLayer.mask=backgroundMaskLayer;
            [backgroundLayer setContentsScale:[UIScreen mainScreen].scale];
            [backgroundLayer setContentsGravity:kCAGravityResizeAspectFill];
            [backgroundLayer setContents:(__bridge id)[UIImage maskImage:coverImage toPath:dpath].CGImage];

            [self.layer.sublayers[0] addSublayer:backgroundLayer];