Skip to content

Instantly share code, notes, and snippets.

@Kyle-Ye
Created June 25, 2024 11:35
Show Gist options
  • Save Kyle-Ye/163c08d87ca27791f82610a7344b679e to your computer and use it in GitHub Desktop.
Save Kyle-Ye/163c08d87ca27791f82610a7344b679e to your computer and use it in GitHub Desktop.
EnlargedTapAreaButton
import UIKit
open class EnlargedTapAreaButton: UIButton {
open var tapAreaInsets: UIEdgeInsets = .zero
public override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
let largerArea = bounds.inset(by: tapAreaInsets.inverted())
return largerArea.contains(point)
}
}
extension UIEdgeInsets {
func inverted() -> UIEdgeInsets {
UIEdgeInsets(top: -top, left: -left, bottom: -bottom, right: -right)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment