I am using the code below to make the shadow for my 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;
It will drop a shadow in the right and bottom like this image.
Now I want to make my ImageView
also have a shadow in top and left.
What should I change in code?
Is possible to make the view contains shadow in top,right,bottom,left by config in code only or I need to create other layout view for shadow? Any help would be great appreciated.
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
If you are still not getting proper shadow, the problem might be the place you added the code. You should call this in viewDidLayoutSubviews when you use UIBezierPath. If you call in ViewDidLoad, you may get wrong result since the views layout process might be unfinished.
Only following code will do the job for your requirement, You don't need to create
UIBezierPath
for shadow path.The best solution for shadow with a rounded corner on the same view and no need to do clipsToBounds or maskToBounds
CGRectInset(self.avatarImageView.bounds, -10.0, -10.0)
Like this:
Swift 3 version:
Little less code for swift 3: