I am trying to add a drop shadow to a UImageView

后端 未结 1 760
盖世英雄少女心
盖世英雄少女心 2021-01-21 06:50

I am trying to add a drop shadow to a UIImage view. I get a shadow but it is clipped to the edges of the image view and I am not sure why since I correctly set the uiimageview.c

相关标签:
1条回答
  • 2021-01-21 07:37

    I believe the CGContextRef you're passed also has clipping set, to prevent basically this exact behavior. You might want to try just adding a CALayer:

    CALayer                         *layer = [CALayer layer];
    CGRect                          bounds = self.bounds;
    
    layer.bounds = bounds;
    layer.position = CGPointMake(bounds.size.width / 2 + 5, bounds.size.height / 2 + 5);
    layer.backgroundColor = [UIColor colorWithWhite: 0.10 alpha: 0.75].CGColor;
    layer.zPosition = -5;
    
    [self.layer addSublayer: layer];
    
    0 讨论(0)
提交回复
热议问题