Last active
December 15, 2015 06:09
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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