在iOS中投放阴影 [英] Drop shadow in ios
本文介绍了在iOS中投放阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在iOS中放置对象阴影?
How to drop an object shadow in iOS?
我的对象是UIImageView,我想放置一个椭圆形阴影.请参考图像以供参考.
My object is UIImageView and i want to drop an elliptical shadow.Please refer image for reference.
推荐答案
最好使用其他图像显示阴影.使用模糊图像或更改图像视图的Alpha.
Better you use another image for showing shadow. Use blur image or change alpha of the imageview.
或者,如果您要通过编程方式进行操作,请尝试:
Or if you want to do it programmatically, try it:
Obj 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
输出:
来自 http://www.innofied.com/implementing-shadow-ios/并了解更多信息:带有圆角和投影?
Taken from http://www.innofied.com/implementing-shadow-ios/ and also have a look to know more: UIView with rounded corners and drop shadow?
这篇关于在iOS中投放阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文