Skip to content

Instantly share code, notes, and snippets.

@mingsai
Created February 12, 2016 18:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mingsai/5c2fb88e1a7902eb50c6 to your computer and use it in GitHub Desktop.
Save mingsai/5c2fb88e1a7902eb50c6 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 pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
//increase touch area for control in all directions by 20
let area = CGRectInset(self.bounds, -margin, -margin)
return CGRectContainsPoint(area, point)
}
}
@thereal1
Copy link

thereal1 commented Jul 5, 2017

Absolute hero.

@myrace31
Copy link

Thanks

@hourlink
Copy link

hourlink commented Nov 4, 2017

Very useful!

@kaishin-r
Copy link

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