I want to make a stretchable button with rounded corners that don't skew. Currently I'm doing it programatically like so:
[self.myButton setImage:[[UIImage imageNamed:@"my-button"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4)] forState:UIControlStateNormal];
Is there any way to do this in IB and save me having to create outlets for all my buttons and littering my viewDidLoad
method with calls like the above?
No. There isn't currently a way to achieve that.
You can however subclass UIButton and override drawRect:
- (void)drawRect:(CGRect)rect
{
UIImage *textFieldBackground = [[UIImage imageNamed:@"my-button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4)];
[textFieldBackground drawInRect:[self bounds]];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With