ASDisplayNode的子类无法添加阴影?

时间:2016-11-29 08:12:07

标签: objective-c layer shadow

子类的ASDisplayNode无法添加阴影?

    _cancleOrderNode = [[ASButtonNode alloc] init];
    [_cancleOrderNode setTitle:@"取消预约" withFont:EBOSystemFont(17) withColor:[UIColor whiteColor] forState:(ASControlStateNormal)];
    _cancleOrderNode.backgroundColor = RGBCOLORV(0x1b7efe);
    _cancleOrderNode.preferredFrameSize = CGSizeMake(100, 40);
    _cancleOrderNode.cornerRadius = 5;
    [self addShadowView:_cancleOrderNode
            withShadowColor:RGBCOLORV(0xd6dae0)
           withShadowOffSet:(CGSizeMake(5, 12))
          withShadowOpacity:0.7];
    [self addSubnode:_cancleOrderNode];
// 添加阴影
- (void)addShadowView:(ASDisplayNode *)targetNode withShadowColor:(UIColor *)shadowColor withShadowOffSet:(CGSize)shadowOffSet withShadowOpacity:(CGFloat)shadowOpacity{

    UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:targetNode.bounds];
    targetNode.layer.masksToBounds = NO;
    targetNode.layer.shadowColor = shadowColor.CGColor;
    targetNode.layer.shadowOffset = shadowOffSet;
    targetNode.layer.shadowOpacity = shadowOpacity;
    targetNode.layer.shadowPath = shadowPath.CGPath;

}

但它不起作用,谁可以帮助我?

1 个答案:

答案 0 :(得分:0)

是的,当我删除 UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:targetNode.bounds];

targetNode.layer.shadowPath = shadowPath.CGPath;

效果很好