Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

When using auto-layout in iOS 6, a UIButton's intrinsic content size appears to include about 10px of padding around the button text. Is there any way to control this padding value? For example, I'd like to be able to do something like this, which would set the padding to 5px on each side:

[button setPadding:UIEdgeInsetsMake(5, 5, 5, 5)];

I have tried setting contentEdgeInsets, titleEdgeInsets, and imageEdgeInsets, all to no avail. Oddly, specifying a negative left or right value in contentEdgeInsets appears to have some effect, but not top or bottom.

Either way, I'd like to be able to specify the actual padding value as a positive number, not an adjustment to the default expressed as a negative number. Anyone know if this is possible?

share|improve this question

1 Answer 1

I'm not sure if you can do this without subclassing UIButton. If you are willing to subclass, overriding this method might do the trick (I have not tried this):

- (UIEdgeInsets)alignmentRectInsets { return UIEdgeInsetsMake(5, 5, 5, 5); }

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.