2

How would I use edge insets to make an image fit inside a button? I'm not sure what values to use for the arguments in UIEdgeInsetsMake(). Could I somehow use the button's width and height to set them?

I want the button to just be an image when not selected. I understand how to do the "when not selected" part, but I have no idea how to use edge insets nor what the term exactly means.

I have this at the moment:

image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)];

[button setImage:image forState:!UIControlStateSelected];

Also, how would I revert to using no image once the button becomes selected?

Sebastian
  • 7,670
  • 5
  • 38
  • 50
John
  • 3,037
  • 8
  • 36
  • 68
  • 1
    Could you provide some more details? What have you tried? Do you want the button to be just an image, an image with text on top, or what? – mbuc91 Mar 06 '13 at 22:32
  • 1
    You will probably find your answer here http://stackoverflow.com/questions/7628004/how-does-uiedgeinsetsmake-works – Rob Mar 06 '13 at 22:40

1 Answers1

-2

I think I am getting what you are saying. Please let me know if I am misunderstanding your question.

Say you have myImage.png. Initialize it as the following:

[button setImage:[UIImage imageNamed:@"myImage.png"] forState:UIControlStateNormal];

Then, assuming you have connected an IBAction for the button in Interface Builder:

- (IBAction)myButtonWasPressed:(UIButton *)sender
{
    [sender setImage:nil];
}
mbuc91
  • 1,270
  • 11
  • 17
  • Thank you, but how about using edge insets to shrink the picture and make it match the button's size? – John Mar 06 '13 at 22:47
  • Using `setBackgroundImage` instead of `setImage` should scale it appropriately. – mbuc91 Mar 06 '13 at 22:50
  • If you are talking about setting the image to a size other than that of the entire button, that is when you would need to use edge insets. – mbuc91 Mar 06 '13 at 23:48