Reputation: 597
For applying shadow effect on view I am using the below code.
func addShadowImage(parentview:UIView){
parentview.layer.shadowColor = UIColor.redColor().CGColor
parentview.layer.masksToBounds = false
//for bottom shadow on view
parentview.layer.shadowOffset = CGSizeMake(0,1.0)
parentview.layer.shadowOpacity = 0.7
parentview.layer.shadowRadius = 1.0
//for bottom and right sides shadow on view
parentview.layer.shadowOffset = CGSizeMake(1.0,1.0)
parentview.layer.shadowOpacity = 1
parentview.layer.shadowRadius = 1.0
//for empty shadow on view
parentview.layer.shadowOffset = CGSizeMake(0,0)
parentview.layer.shadowOpacity = 1
parentview.layer.shadowRadius = 0
//for bottom and right and left sides shadow on view
parentview.layer.shadowOffset = CGSizeMake(0,2.0)
parentview.layer.shadowOpacity = 1
parentview.layer.shadowRadius = 2.0
//for four sides shadow on view
parentview.layer.shadowOffset = CGSizeMake(0,0)
parentview.layer.shadowOpacity = 1.0
parentview.layer.shadowRadius = 5.0
}
Now simply call the above function with parameter type is UIView self.addShadowImage(yourViewObject)
Then it's working fine, But this shadow effected on all its subviews.
So now I want to apply a shadow effect on specific view and specific side(i.e either left or right/bottom/top).
Upvotes: 1
Views: 3994