Skip to content

Instantly share code, notes, and snippets.

@seanwolter
Last active December 15, 2015 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanwolter/5214606 to your computer and use it in GitHub Desktop.
Save seanwolter/5214606 to your computer and use it in GitHub Desktop.
set a button's background image in interface builder then stretch it in code
- (void)awakeFromNib
{
[self strechImageForControlState:UIControlStateNormal];
[self strechImageForControlState:UIControlStateDisabled];
[self strechImageForControlState:UIControlStateHighlighted];
[self strechImageForControlState:UIControlStateSelected];
}
- (void)strechImageForControlState:(UIControlState)controlState
{
UIEdgeInsets insets = UIEdgeInsetsMake(25.0, 25.0, 25.0, 25.0);
UIImage *image = [self backgroundImageForState:controlState];
//these are just example insets, I'm not sure if they're correct
image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
[self setBackgroundImage:image forState:controlState];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment