Skip to content

Instantly share code, notes, and snippets.

@mingsai
Created February 12, 2016 18:08
Show Gist options
  • 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)
}
}
@kaishin-r
Copy link

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