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
There is a very detailed explanation about this here: https://www.hackingwithswift.com/example-code/uikit/how-to-add-a-shadow-to-a-uiview.
If someone is straggling with no top shadow in a collection view then this may help:
I know that this may be obvious for some people, but if you have a CollectionView with header and cell, make sure that you have space between the header and the cell, otherwise, the top shadow of the cell will be blocked by the header.
To add space, just use the insetsForSectionAt section.
Without using UIBezierPath, CGSize.zero is the key here
For UIView and Adding shadow, remember to set background color to the UIView.
If the background color is clearColor, no shadow appears.
//If you’ve tried this before, you know exactly what happens. The corners will be rounded, but the shadow will be missing. If you set masksToBounds to false, the shadow will appear, but the corners will not be rounded. //to get Shadow with corner radius Add super view for container view with clear color and apply shadow for super view ,Apply corner radius for container View. try it.