Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kaishin-r/fa7a476d981aa66c9e9eccd01dde59f2 to your computer and use it in GitHub Desktop.
Save kaishin-r/fa7a476d981aa66c9e9eccd01dde59f2 to your computer and use it in GitHub Desktop.
A Swift UIButton subclass to expand the touch area of the button.
//
// MNGExpandedTouchAreaButton.swift
//
//
// Created by Tommie Carter on 7/7/15.
// Copyright © 2015 MING Technology. All rights reserved.
//
import UIKit
@IBDesignable
class MNGExpandedTouchAreaButton: UIButton {
@IBInspectable var margin: CGFloat = 20.0
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
// increase touch area for control in all directions by 20
let area = self.bounds.insetBy(dx: -margin, dy: -margin)
return area.contains(point)
}
}
@kaishin-r
Copy link
Author

Update for Swift 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment