0

I'm trying to have an UIButton with an image in the middle of it. I want this button to have edge insets of 10px. When I set these, I have the correct visual result but I can only click in a little area of this button.

How can I have the same visual but be able to click on the whole button ?

Here is my code :

self.descriptionViewMaleButton.setImage(UIImage(icon: "icon-male", backgroundColor: UIColor.whiteColor(), iconColor: UIColor.blackColor(), iconScale: 1.0, andSize: CGSize(width: 50, height: 50)), forState: UIControlState.Normal)
self.descriptionViewMaleButton.layer.borderColor = UIColor.grayColor().CGColor
self.descriptionViewMaleButton.layer.borderWidth = 1.0
self.descriptionViewMaleButton.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10)

And the visual result :

enter image description here

EDIT : I am able to click on the whole button but it is highlighting only the image.

EDIT : I "fixed" that by implementing the highlighting myself. Anyway, if someones know more about this issue, I would be glad to know about it.

Aeradriel
  • 1,224
  • 14
  • 36
  • So the buttons are 10x10? And the images are 50x50? Or am I missing something because it looks like making the buttons fit the image will solve the problem. – TheCodeComposer Jul 18 '15 at 20:23
  • I am most probably wrong but I thought edge insets were kind of like padding in CSS. All I want to do is adding white space between border and image. – Aeradriel Jul 18 '15 at 20:55

0 Answers0