Reputation: 3
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?
Upvotes: 0
Views: 332
Reputation: 8808
The iOS file system is case sensitive, unlike the sinulator's. I'd start by checking that "Images" directory.
(Quick test if I'm barking up the wrong tree: does the +imageNamed:
call return nil?)
Upvotes: 1
Reputation: 33101
Use
[UIImage imageNamed:@"whitebutton.png"]
and
[UIImage imageNamed:@"bluebutton.png"]
Regardless of how you have it visually organized in Xcode, it all gets flattened in the bundle
Upvotes: 0
Reputation: 78353
Your resources are going to get flattened in your app bundle. Also, the filesystem on iOS is case sensitive while the filesystem on Mac OS X is case preserving, so make sure the actual filenames of your images are case-correct. If they are, just remove the Images/
prefix and it should work:
[UIImage imageNamed:@"bluebutton"];
Also, if the image is a png type, you don't need to specify the file extension with imageNamed:
.
Upvotes: 0
Reputation: 4029
You should add whitebutton.png and bluebutton.png to your project. And call imageNamed:@"filename"
not imageNamed:@"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
Upvotes: 0