我正在使用下面的代码为我的阴影制作阴影ImageView
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:self.avatarImageView.bounds];
self.avatarImageView.layer.masksToBounds = NO;
self.avatarImageView.layer.shadowColor = [UIColor blackColor].CGColor;
self.avatarImageView.layer.shadowOffset = CGSizeMake(5.0f, 5.0f);
self.avatarImageView.layer.shadowOpacity = 0.8f;
self.avatarImageView.layer.shadowPath = shadowPath.CGPath;
它会像下图一样在右侧和底部留下阴影。
现在我想做我的ImageView
顶部和左侧也有一个阴影。
我应该在代码中更改什么?
是否可以仅通过代码中的配置使视图在顶部、右侧、底部、左侧包含阴影,或者我需要为阴影创建其他布局视图?任何帮助将不胜感激。
Here is what I want to achieve
Update
Thank @Dipen Panchasara for give a simple solution. Follow @Dipen Panchasara (with the shadow color is black) I will have the shadow image like this
只需以下代码即可满足您的要求,您不需要创建UIBezierPath
对于阴影路径。
// *** Set masks bounds to NO to display shadow visible ***
self.avatarImageView.layer.masksToBounds = NO;
// *** Set light gray color as shown in sample ***
self.avatarImageView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
// *** *** Use following to add Shadow top, left ***
self.avatarImageView.layer.shadowOffset = CGSizeMake(-5.0f, -5.0f);
// *** Use following to add Shadow bottom, right ***
//self.avatarImageView.layer.shadowOffset = CGSizeMake(5.0f, 5.0f);
// *** Use following to add Shadow top, left, bottom, right ***
// avatarImageView.layer.shadowOffset = CGSizeZero;
// avatarImageView.layer.shadowRadius = 5.0f;
// *** Set shadowOpacity to full (1) ***
self.avatarImageView.layer.shadowOpacity = 1.0f;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)