How can I increase the Tap Area for UIButton?

uibarbuttonitem increase touch area
increase clickable area of uibutton swift
button click area swift
uibutton extend hit area
increase tappable area of uibutton swift
swiftui button hit area
uicontrol tap area
cgrectcontainspoint swift

I use UIButton with auto layout. When images are small the tap area is also small. I could imagine several approaches to fix this:

  1. increase the image size, i.e., place a transparent area around the image. This is not good because when you position the image you have to keep the extra transparent border in mind.
  2. use CGRectInset and increase the size. This does not work well with auto layout because using auto layout it will fall back to the original image size.

Beside the two approaches above is there a better solution to increase the tap area of a UIButton?


You can simply adjust the content inset of the button to get your desired size. In code, it will look like this:

button.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)

// or if you specifically want to adjust around the image, instead use button.imageEdgeInsets

In interface builder, it will look like this:

Increasing the tap area of a UIButton, out), which reminded me of a problem I solved the other week: I wanted to increase a UIButton's tap area, without increasing the button's frame. Increasing the tap area of a UIButton The other day, Soroush wrote a great post about hitTest(_:with:) (you should check it out), which reminded me of a problem I solved the other week: I wanted to increase a UIButton ’s tap area, without increasing the button’s frame.


Very easy. Create a custom UIButton class. Then override pointInside... method and change the value as you want.

#import "CustomButton.h"

@implementation CustomButton

-(BOOL) pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
    CGRect newArea = CGRectMake(self.bounds.origin.x - 10, self.bounds.origin.y - 10, self.bounds.size.width + 20, self.bounds.size.height + 20);

    return CGRectContainsPoint(newArea, point);
}
@end

It will take more 10 points touch area for every side.

Increasing the tap area of a UIButton : swift, Increasing the tap area of a UIButton What's the difference between this and a big button with insets on its image? level 2 It can expand below other items. At (1) we might need to convert between coordinate systems and at (2) we might also want to check if the button is enabled and visible, if it can have different states. If you google increase uibutton tap area , you’ll get quite a few results, mentioning either increasing imageEdgeInsets / titleEdgeInsets (not quite what we want), or using


You can set the button EdgeInsets in storyboard or via code. The size of button should be bigger in height and width than image set to button.

Note: After Xcode8, setting content inset is available in size inspecor

Or you can also use image view with tap gesture on it for action while taping on image view. Make sure to tick User Interaction Enabled for imageview on storyboard for gesture to work. Make image view bigger than image to set on it and set image on it. Now set the mode of image view image to center on storyboard/interface builder.

You can tap on image to do action.

Hope it will be helpful.

Increasing the tap area of UIButtons made with PaintCode, Whether you're a developer or not, every iPhone user has experienced the case where he or she tries to tap a button (with an image and  Inside a ViewControllers view I have a UIStackView which contains three buttons. I want these buttons to have an increased tap area. I have tried solutions found here: How can I increase the Tap A


I confirm that Syed's solution works well even with autolayout. Here's the Swift 4.x version:

import UIKit

class BeepSmallButton: UIButton {

    // MARK: - Functions

    override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
        let newArea = CGRect(
            x: self.bounds.origin.x - 5.0,
            y: self.bounds.origin.y - 5.0,
            width: self.bounds.size.width + 10.0,
            height: self.bounds.size.height + 20.0
        )
        return newArea.contains(point)
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

How can I increase the Tap Area for UIButton?, I use UIButton with auto layout. When images are small the tap area is also small. I could imagine several approaches to fix this: increase the  Increasing the tap area of UIButtons made with PaintCode. Whether you’re a developer or not, every iPhone user has experienced the case where he or she tries to tap a button (with an image and nothing happens. Most likely because the user missed the button and pressed next to it.


Swift 4 • Xcode 9

You can select programmatically as -

For Image -

button.imageEdgeInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)

For Title -

button.titleEdgeInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)

A Swift UIButton subclass to expand the touch area of the button , //increase touch area for control in all directions by 20. let area = CGRectInset(​self.bounds, -margin, -margin). return CGRectContainsPoint(area  Use the design approach you like (Interface Builder / Visual Format Language) together with Autolayout and layout the UIButton with the required size. Set title or image as content and use a transparent image with the size of the tapable area as background image.


Swift: Expand UIButton's clickable area – swifty thoughts, Swift: Expand UIButton's clickable area. We all know the drill – there's a button that doesn't always detect touch events due to various reasons  It is looked as the right button in above image. Now the requirement is that the selection area of this button should be more than then the uibutton image. So that the user will be able to click the button easily by touching on near by area of particular button. [togglebutton setImageEdgeInsets: UIEdgeInsetsMake( 0, -30, 0, -25)];


iPhone Tip: Larger Hit Area for UIButton, 2010-08-18 Update: I added a section explaining how to programmatically grow the touchable area of a UIButton via hi Well, you can place your UIButton inside a transparent and slightly bigger UIView, and then catch the touch events on the UIView instance as in the UIButton. That way, you will still have your button, but with a bigger touch area.


Creating Info Button and Increasing Touch Area, Speaking of touching the info button, one change I recommend is to increase the frame size of info button so there is a larger area on the screen  objective-c,uitableview,uibutton,custom-cell. You can create custom cells or can manage UITableviewCell by tags. On Your button tap event, get Tableviewcells one by one and validate the textbox values with in cell. To identify cells You can check class of cell and tag for that cell. Remember in cellForRowAtIndexPath you must assign tag