首先峦甩,我們得繼承一個(gè)UIButton,然后重寫(xiě) - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event 這個(gè)方法佩迟,蘋(píng)果的概念是點(diǎn)擊區(qū)域最好不小于44 point喻频,所以我們根據(jù)這個(gè)數(shù)值計(jì)算我們的點(diǎn)擊區(qū)域。上代碼寨典。
自定義按鈕 擴(kuò)大按鈕點(diǎn)擊范圍
```
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event
{
CGRectbounds =self.bounds;
CGFloatwidthDelta =44.0- bounds.size.width;
CGFloatheightDelta =44.0- bounds.size.height;
bounds =CGRectInset(bounds, -0.5* widthDelta, -0.5* heightDelta);//注意這里是負(fù)數(shù)耀盗,擴(kuò)大了之前的bounds的范圍
returnCGRectContainsPoint(bounds, point);
}
```