Making the UIButton hit area larger than the default hit area
Why did you simple create a custom button which are at the size you want for your hit box but include a margin inside it's content ?
Or may be with a UIEdgeInsets
put on your button, your button will have a margin so the hit box seems bigger than button with this solution..
How can I increase the Tap Area for 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:
UIButton hit area is too big
Although I still have no idea what's causing this bug. (maybe a bug in the iOS7 sdk...?) I fixed it by subclassing UIButton and doing a hit test to check if I'm really clicking the button.
#import "TTButton.h"
@implementation TTButton {}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (CGRectContainsPoint([self bounds], point)) {
NSLog(@"inside");
return self;
}
return nil;
}
@end
How to increase selection area of UIButton?
You can achieve this by setting the button's contentEdgeInsets
, for example:
toggleButton.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0); //set as you require
Related Topics
String Replacement in Objective-C
How to Know When Uitableview Did Scroll to Bottom in Iphone
Manual Language Selection in an Ios-App (Iphone and Ipad)
Library Not Loaded: @Rpath/Fblpromises.Framework/Fblpromises iOS 13.3.1
Add Image to Uialertaction in Uialertcontroller
How to Launch Safari and Open Url from iOS App
Importing Project-Swift.H into a Objective-C Class...File Not Found
Converting Hex String to Nsdata in Swift
How to Ignore Touch Events and Pass Them to Another Subview'S Uicontrol Objects
Reloaddata() of Uitableview With Dynamic Cell Heights Causes Jumpy Scrolling
When to Use Dequeuereusablecellwithidentifier VS Dequeuereusablecellwithidentifier: Forindexpath
Ios 7 Textkit - How to Insert Images Inline With Text
Didregisterforremotenotificationswithdevicetoken Not Called in Ios8, But Didregister...Settings Is
How to Determine the Os Version At Runtime in Os X or iOS (Without Using Gestalt)
Displaying a Stock iOS Notification Banner When Your App Is Open and in the Foreground