gpt4 book ai didi

ios - 如何向被屏蔽自定义内容的CALayer添加阴影

转载 作者:行者123 更新时间:2023-12-01 17:12:09 25 4
gpt4 key购买 nike

我正在尝试向遮罩的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;


}

最佳答案

像这样尝试设置遮罩的阴影属性而不是view.layer的阴影属性

//mask.shadowColor = [UIColor blackColor].CGColor;
mask.shadowOffset = CGSizeMake(5, 5);
mask.shadowRadius = 2;
mask.shadowOpacity = 1;

请注意,shadowColor属性将被忽略,并且获得与视图相同的颜色。

关于ios - 如何向被屏蔽自定义内容的CALayer添加阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23535686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com