TotoroTotoro
TotoroTotoro

Reputation: 17622

UIButton with cust. background looks bad when pressed

I have a UIButton with a custom background that I set in the Interface Builder (see picture). It looks nice, but in the pressed state it gets really ugly (see the 2nd picture). What's going on here?

Normal:

see picture

Pressed:

enter image description here

Upvotes: 0

Views: 576

Answers (2)

QED
QED

Reputation: 9933

Post some code or maybe the image itself. It looks as if you might need to declare your 'pressed' image with one of UIImage's resizableImage* methods. It's stretching to fill the button rect.

Also, I'm fond of the MOButton and MOGlassButton classes used in the iPhone SOCKS project (handy in itself).

Update

The following worked for me, it even animated it dark when pressed:

enter image description here

Upvotes: 0

anticyclope
anticyclope

Reputation: 1587

[btn setBackgroundImage:[[UIImage imageNamed:@"button_red.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(12, 12, 20, 12)] forState:UIControlStateNormal];
[btn setBackgroundImage:[[UIImage imageNamed:@"button_red_pressed.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(12, 12, 20, 12)] forState:UIControlStateHighlighted];

This should solve the problem.

Also, change your button style to Custom, this will remove that blue button background.

Upvotes: 1

Related Questions