Search code examples
objective-clayershadow

The subclasses of ASDisplayNode can not add the shadow?


The ASDisplayNode of subclasses can not add the shadow?

    _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;

}

but it did not work,Who can help me?


Solution

  • yes ,when i delete UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:targetNode.bounds]; and

    targetNode.layer.shadowPath = shadowPath.CGPath;

    It works well