Reputation: 4224
I have been adding a bottom shadow to a UIButton
this way:
class MyButton: UIButton {
override func layoutSubviews() {
super.layoutSubviews()
self.layer.shadowOpacity = 0.33
self.layer.shadowRadius = 4.0
self.layer.shadowColor = UIColor.blue.cgColor
self.layer.shadowOffset = CGSize(width: 0.0, height: 6.0)
}
}
The result I'm getting:
This works fine but I would like now to shrink the shadow width in order to have this rendering instead (picture from Sketch) :
Any idea of how to handle this?
Thanks for your help!
Upvotes: 0
Views: 67
Reputation: 665
Use layer's shadowPath property. add below code to layoutSubviews method and try.
let path = UIBezierPath(roundedRect: bounds.insetBy(dx: 10, dy: 0), cornerRadius: 4.0)
self.layer.shadowPath = path.cgPath
Upvotes: 1
Reputation: 4156
If you do not find a more suitable answer, then try this: Add a UIView under the button with the desired size and it is for her to make a shadow.
Upvotes: 0