I have a UIImageView that I want to add a shadow behind. I wish that apple had that as a property but they have to make lots of things hard for us programmers so I need to ask this question.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s a better and easier way to do this. UIImageView inherits from UIView so it has a layer property. You can access the layer’s shadow properties and bam, you got a shadow.
If you have the UIImageView as an IBOutlet to a nib file, you can just implement the awakeFromNib
e.g.
Objective-C
Don’t forget to
#import "QuartzCore/CALayer.h"For Swift, you can go about it multiple ways. Create a class extension, subclass, or an imageView instance. Whichever the way, the process is the same in modifying the layers shadow property.
Swift 3