Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you set UIEdgeInsets through Interface Builder?

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?

like image 931
lmirosevic Avatar asked Aug 23 '12 06:08

lmirosevic


1 Answers

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]];
} 
like image 98
nicktmro Avatar answered Sep 21 '22 13:09

nicktmro