Reputation: 2057
I want a view with some shadow and corner radius the problem i have when i have shadow the corner radius is not available i set masktobound to false and i have added this code
func setShadow() {
cardCBView.layer.cornerRadius = 10
cardCBView.layer.borderWidth = 1.0
cardCBView.layer.borderColor = #colorLiteral(red: 0.8980392157, green: 0.8980392157, blue: 0.8980392157, alpha: 0)
cardCBView.layer.shadowColor = UIColor.black.cgColor
cardCBView.layer.shadowOffset = CGSize.zero
cardCBView.layer.shadowOpacity = 0.2
cardCBView.layer.shadowRadius = 4.0
}
i have result like image : with masktobound off
when i put different color for bordercolor
how can i have shadow and radius corner ?
any help is appreciated
Upvotes: 1
Views: 2727
Reputation: 21
There is a way using CAShapeLayer
as background to do it
let bgLayer = CAShapeLayer()
bgLayer.frame = bounds
bgLayer.shadowOffset = CGSize(width: 0, height: -1)
bgLayer.shadowOpacity = 0.8
bgLayer.shadowRadius = 1.0
bgLayer.shadowColor = UIColor.shadowBackground.cgColor
bgLayer.fillColor = UIColor.orderPopBg.cgColor
let path = CGMutablePath()
path.addRoundedRect(in: bounds, cornerWidth: 10, cornerHeight: 10)
bgLayer.path = path
layer.addSublayer(bgLayer)
Change the shadowColor and fillColor to yours.
Upvotes: 0
Reputation: 14397
There are three steps through which you can achieve both shadow and corers
clipToBounds = true
clipToBounds = false
Upvotes: 1