gpt4 book ai didi

ios - 为什么阴影半径也会对圆的内部产生影响?

转载 作者:行者123 更新时间:2023-12-01 16:28:34 26 4
gpt4 key购买 nike

我想将阴影应用到圆圈的外层空间。但是阴影半径也在内部生效,所以核心圆看起来比实际要小

我这样画圆圈:

self.shadowLayer = [CALayer layer];
self.shadowLayer.frame = self.view.layer.bounds;
self.shadowLayer.shadowColor = [UIColor blueColor].CGColor;
self.shadowLayer.shadowRadius = 0;
self.shadowLayer.shadowOpacity = 1.0;
self.shadowLayer.shadowOffset = CGSizeMake(0,0);
CGRect frame = CGRectMake(0 , 50, self.view.bounds.size.width, self.view.bounds.size.width);
self.shadowLayer.shadowPath = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(frame, 40, 40)].CGPath;
[self.view.layer addSublayer:self.shadowLayer];

结果是正常的圆圈:
enter image description here

但是如果我改变 self.shadowLayer.shadowRadius从 0 到 30 结果是:
enter image description here

可以看到,核心中纯色的尺寸缩小了。我希望阴影仅在路径外部生效,并且纯色的大小与 shadow radius = 0 的情况完全相同.截图后添加红色曲线。有没有看大小的区别。

更新
一个想法是减少 shadowRadius一半并将框架扩大相同的数量。我认为这将足够好。

最佳答案

您可以使用 NSShadow并绘制自定义 UIView来产生你想要的效果。

使用代码绘制自定义 View :

- (void)drawRect: (CGRect)frame
{
//// General Declarations
CGContextRef context = UIGraphicsGetCurrentContext();

//// Color Declarations
UIColor* color4 = [UIColor colorWithRed: 0.301 green: 0.261 blue: 0.968 alpha: 1];
UIColor* shadowColor = [UIColor colorWithRed: 0 green: 0 blue: 0 alpha: 1];

//// Shadow Declarations
NSShadow* shadow = [[NSShadow alloc] init];
[shadow setShadowColor: shadowColor];
[shadow setShadowOffset: CGSizeMake(0.1, -0.1)];
[shadow setShadowBlurRadius: 11];

//// Oval Drawing
UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(CGRectGetMinX(frame) + 69, CGRectGetMinY(frame) + 14, 72, 70)];
CGContextSaveGState(context);
CGContextSetShadowWithColor(context, shadow.shadowOffset, shadow.shadowBlurRadius, [shadow.shadowColor CGColor]);
[color4 setFill];
[ovalPath fill];
CGContextRestoreGState(context);
}

这给出了圆形边界外的阴影效果:

enter image description here

关于ios - 为什么阴影半径也会对圆的内部产生影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33676787/

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