There is a better and easier way to do this. UIImageView inherits from UIView, so it has a layer property. You can access the shadow properties of the shadow and bam, you have the shadow.
If you have UIImageView as an IBOutlet for the nib file, you can just implement awakeFromNib for example.
Objective-c
- (void)awakeFromNib { imageView.layer.shadowColor = [UIColor purpleColor].CGColor; imageView.layer.shadowOffset = CGSizeMake(0, 1); imageView.layer.shadowOpacity = 1; imageView.layer.shadowRadius = 1.0; imageView.clipsToBounds = NO; }
Do not forget #import "QuartzCore/CALayer.h"
There are several ways you can use Swift. Create a class extension, subclass, or imageView instance. In whatever way, this process does not change when the property of layer tags changes.
Swift 3
override func awakeFromNib() { super.awakeFromNib() imageView.layer.shadowColor = UIColor.purple.cgColor imageView.layer.shadowOffset = CGSize(width: 0, height: 1) imageView.layer.shadowOpacity = 1 imageView.layer.shadowRadius = 1.0 imageView.clipsToBounds = false }
Alex Nguyen Oct 01 '10 at 23:14 2010-10-01 23:14
source share