Skip to content
A small helper library to effortlessly increase the hit test area of a view, control or a button.
Branch: master
Clone or download
Latest commit aa7c8b9 Jun 12, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example Added a hit testing category that allows to change any view hit test … May 30, 2016
Images Updated README. Jul 25, 2015
KGHitTestingViews Fixed missing license. Jun 12, 2016
Tests
.gitignore First clean history commit. May 12, 2015
KGHitTestingViews.podspec Updated pod spec. May 31, 2016
LICENSE First clean history commit. May 12, 2015
README.md Updated README, Podspec, and cleaned up bracket style of UIView categ… May 30, 2016

README.md

Overview

KGHitTestingViews is a small helper library to effortlessly increase the hit test area of a view.

It's common to display buttons as small as 20 x 20 points. However, iOS User Interface Guidelines recommends that all tappable controls have at least a 44 x 44 point hit area. A common solution to this problem involves making a large button containing a small image, but this solution impacts positioning constraints relative to the small image and makes the layout generally more awkward. KGHitTestingViews aims to solve this problem in a simple manner.

Installation

To install using CocoaPods, add the following to your project Podfile:

pod 'KGHitTestingViews'

Alternatively, drag and drop all of the files in the KGHitTestingViews folder into your Xcode project, agreeing to copy files if needed.

How to Use

In Code (Category):

The easiest way to use KGHitTestingViews is to use the UIView category: "UIView+KGHitTesting.h". No subclassing required!

@interface UIView (KGHitTesting)
- (void)setMinimumHitTestWidth:(CGFloat)width height:(CGFloat)height;
@end

In Code (Subclassing):

Subclass KGHitTestingView or KGHitTestingControl or KGHitTestingButton and set minimumHitTestHeight and minimumHitTestWidth to the desired size of the hit test area:

@interface ButtonSubclass : KGHitTestingButton
@end
- (void)setup {
	self.minimumHitTestWidth = 44.0;
	self.minimumHitTestHeight = 44.0;
}

In Interface Builder (Subclassing):

Subclass KGHitTestingView or KGHitTestingControl or KGHitTestingButton in the "Identify Inspector" and set the width and height values in the "Attributes Inspector."

Important note:

The height and width of the hit test area are minimums. If you specify a smaller hit area width or height than what the bounds specify, the bounds width or height will be used.

Swift Support

KGHitTestingViews works with Swift! Just follow the "How to Use" section.

FAQ

###What is hit testing?

"The process of determining whether a user-controlled cursor (such as a mouse cursor or touch-point on a touch-screen interface) intersects a given graphical object (such as a shape, line, or curve) drawn on the screen." - Wikipedia

###Why override -pointInside:? I thought this is hit testing. Hit test (-hitTest:) is a more-complex algorithmic test that involves looping through subviews. Point inside (-pointInside:) is a simple geometric test which checks whether a CGPoint is within the bounds of a given view. For the purposes of increasing the touch area, we only need to modify the geometric calculation. For more, check out this nicely written blog about hit-testing.

Credits

Created and maintained by Krisjanis Gaidis.

Contributions:

License

KGHitTestingViews is released under the MIT license. See LICENSE for details.

You can’t perform that action at this time.