I'm trying to set a background image for a CCButton and make sure it stretches or minimizes to the exact size of the CCButton:
-(void)setBackgroundSpriteFrame: (NSString*)spriteFrameFileName
{
NSString* fullFileName = [NSString stringWithFormat:@"%@.png", spriteFrameFileName];
CCSpriteFrame *spriteFrame = [CCSpriteFrame frameWithImageNamed:fullFileName];
[super setBackgroundSpriteFrame:spriteFrame forState:CCControlStateNormal];
double scaleValue = self.contentSize.height / spriteFrame.rect.size.height;
[self.background setScale:scaleValue];
self.fileName = spriteFrameFileName;
}
This method resides inside a class that inherits from CCButton.
The problem is that I see the background image but it is squeezed in a weird way (see image) and not minimized\stretched to the size of the button.
Please note that the image and the button are squares so no need to scale X\Y separately, and also note that the CCButton is generated with SprtieBuilder and not by code.
Thanks