gpt4 book ai didi

ios - 在 ios 中放置阴影

转载 作者:行者123 更新时间:2023-11-28 19:34:40 25 4
gpt4 key购买 nike

如何在 iOS 中放置对象阴影?

我的对象是 UIImageView,我想投下椭圆形阴影。请引用图片以供引用。 enter image description here

最佳答案

最好使用另一张图片来显示阴影。使用模糊图像或更改 imageview 的 alpha。

或者,如果您想以编程方式执行此操作,请尝试:

objective-c :

//create elliptical shadow for image through UIBezierPath
CGRect ovalRect = CGRectMake(0.0f, _imageView.frame.size.height + 10, _imageView.frame.size.width, 15);
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:ovalRect];

//applying shadow to path
_imageView.layer.shadowColor = kShadowColor.CGColor;
_imageView.layer.shadowOffset = CGSizeMake(0.0, 0.0);
_imageView.layer.shadowOpacity = 1.0;
_imageView.layer.shadowRadius = 3.0;
_imageView.layer.shadowPath = path.CGPath;

swift :

//create elliptical shdow forimage through UIBezierPath
var ovalRect = CGRectMake(0.0, imageView.frame.size.height + 10, imageView.frame.size.width, 15)
var path = UIBezierPath(ovalInRect: ovalRect)

//applying shadow to path
imageView.layer.shadowColor = UIColor(white: 0.0, alpha: 0.5).CGColor
imageView.layer.shadowOffset = CGSizeMake(0.0, 0.0)
imageView.layer.shadowOpacity = 1.0
imageView.layer.shadowRadius = 3.0
imageView.layer.shadowPath = path.CGPath

输出:

enter image description here

取自http://www.innofied.com/implementing-shadow-ios/并查看更多信息:UIView with rounded corners and drop shadow?

关于ios - 在 ios 中放置阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40155443/

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