Skip to content

Instantly share code, notes, and snippets.

@jrturton
Created June 27, 2013 13:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrturton/5876323 to your computer and use it in GitHub Desktop.
Save jrturton/5876323 to your computer and use it in GitHub Desktop.
Handy inset adjustments for UIButtons
@implementation UIButton (Insets)
-(void)addSpaceBetweenImageAndText:(CGFloat)space
{
self.titleEdgeInsets = UIEdgeInsetsMake(0.0, space, 0.0, -space);
self.contentEdgeInsets = UIEdgeInsetsMake(0.0, space, 0.0, 2.0 * space);
}
- (void)addSpaceBetweenImageAndText:(CGFloat)space withLeftAndRightPadding:(CGFloat)padding
{
self.titleEdgeInsets = UIEdgeInsetsMake(0.0, space, 0.0, -space);
self.contentEdgeInsets = UIEdgeInsetsMake(0.0, padding, 0.0, padding);
}
- (void)positionTextBelowImage
{
self.titleEdgeInsets = UIEdgeInsetsMake(0.0, -[self imageForState:UIControlStateNormal].size.width, -self.titleLabel.frame.size.height - 10.0, 0.0);
self.imageEdgeInsets = UIEdgeInsetsMake(-self.titleLabel.frame.size.height, 0.0, 0.0, -self.titleLabel.frame.size.width);
[self sizeToFit];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment