简体   繁体   中英

Making the UIButton hit area larger than the default hit area

I'm trying to make the hit area of a UIButton larger.

I tried using:

myButton.setHitTestEdgeInsects

but Xcode doesn't recognise it.

I also tried:

myButton.contentEdgeInsets = (UIEdgeInsetsMake(5, 5, 5, 5))

but it changes the look of my button.

Im using swift so for I added the necessary files to the import header. i guess the problem is there. Can someone help with that or tell about a similar swift function? here is the func im trying to use -

Edit - I think i'm getting closer to the solution because im writing in swift xcode recognised it like that

 myButton.hitTestEdgeInsets = UIEdgeInsetsMake(-200, -200, -200, -200)

instead of -

 myButton.setHitTestEdgeInsets = UIEdgeInsetsMake(-200, -200, -200, -200)

so now xcode recognises it but still i have no change in my 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..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM