So I’m trying to implement a custom button in my iOS app to replace the default rounded rectangle button. Heres a code snippet:
UIImage *normalImage = [[UIImage imageNamed:@"Images/whitebutton.png"] stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
UIImage *pressedImage = [[UIImage imageNamed:@"Images/bluebutton.png"] stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
[self.theButton setBackgroundImage:normalImage forState:UIControlStateNormal];
[self.theButton setBackgroundImage:pressedImage forState:UIControlStateHighlighted];
When I run it in the simulator everything works fine, my custom button shows up. However, when I run it on my actual device the button just appears as the default one with no customisation at all. Anybody got any idea where I’m going wrong?
You should add whitebutton.png and bluebutton.png to your project. And call
imageNamed:@"filename"notimageNamed:@"file path". Also , when running on the simulator there is no problem with case sensitivity. On the device , you have to type the correct name of the file because it IS case sensitive.Hope this helps.
Cheers,
George