Here is my Button class.
@IBDesignable
class Button: UIButton {
var cornerRadii = CGSize()
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
cornerRadii = CGSize(width: cornerRadius, height: cornerRadius)
}
}
@IBInspectable var color: UIColor = .green
override func draw(_ rect: CGRect) {
super.draw(rect)
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: cornerRadii)
let shapeLayer = CAShapeLayer()
shapeLayer.frame = self.layer.bounds
shapeLayer.path = path.cgPath
layer.mask = shapeLayer
color.setFill()
path.fill()
}
}
So everything works pretty well. My button has a half-circe form so actually when I click at the empty corner of the button frame I do not expect it to be pressed, but it actually happens. I thought that mask can help me with this issue but I didn't manage do make it.
So the questing how I can create a button with two empty corners that are not clickable?
Ovveride
point inside
method for your customButton
: