Ios 如何向CALayer添加隐藏到自定义内容的阴影
我正在尝试将阴影添加到遮罩的Ios 如何向CALayer添加隐藏到自定义内容的阴影,ios,objective-c,uiview,calayer,Ios,Objective C,Uiview,Calayer,我正在尝试将阴影添加到遮罩的UIView(来自UIImage),但我相信,因为视图被遮罩到边界,masksToBounds=YES阴影不会显示 如果确实是这样,那么我如何才能在蒙版图像周围绘制阴影呢 -(UIView *)modifyViewWithMask:(UIView *)view { view.alpha = 0.5; UIView *blackView = [[UIView alloc] initWithFrame:view.bounds]; blackView
UIView
(来自UIImage
),但我相信,因为视图被遮罩到边界,masksToBounds=YES
阴影不会显示
如果确实是这样,那么我如何才能在蒙版图像周围绘制阴影呢
-(UIView *)modifyViewWithMask:(UIView *)view
{
view.alpha = 0.5;
UIView *blackView = [[UIView alloc] initWithFrame:view.bounds];
blackView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
blackView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
[view addSubview:blackView];
UIImage* bubbleImage = [UIImage imageNamed:@"Bubble"];
CALayer* mask = [CALayer layer];
mask.contents = (id)[bubbleImage CGImage];
mask.frame = CGRectMake(0, 0, view.frame.size.width, view.frame.size.height);
view.layer.mask = mask;
view.layer.masksToBounds = YES;
view.layer.shadowColor = [UIColor blackColor].CGColor;
view.layer.shadowOffset = CGSizeMake(10, 10);
view.layer.shadowRadius = 10;
view.layer.shadowOpacity = 1;
}