Picture doesn't show on iPhone when running app - ios

I have set the backgroundColor to a picture which is located in the project folder. When I run the app in the simulator the pic is shown. But when running on my real iPhone it's just white. What can be causing this? Could it be because I have <0.5gb free on both the computer and iPhone?

I had similar situation.
It seems the simulator - Xcode is cacheing the image somewhere, but at build time is loosing.
Try: uninstall the app from simulator, device.
Clean the project.
Force close XCode, not just the project, close it.
Open, clean project, build
At this step should match the device and simulator behaviour, hopefully it is there the desired image.

Please check spelling of the image name you used. In actual devices it's case sensitive.

That should be plenty of free memory. When adding the file to your project, and make sure you choose the options for the image to be copied into the project and to be part of the target.
EDIT: my above suggestion is only useful if the UIImageView you are trying to load points to a picture, and I guess in this case you are just using a blank UIImageView and setting background color.
Also, you might want to look at the arrangement (ie. send to back, send to front, etc. Try sending to front in case there was something in front of it blocking the view) I think these options are in the menu bar under Design --> Arrangement

Could you post some code?
You'll want to add the image not as a backgroundColor, but as a UIImageView subview.
// load the image
UIImage *image = [UIImage imageNamed:#"image.png"];
// create the image view using the image
UIImageView *imageView = [UIImageView alloc] initWithImage:image];
// add the image view as a subview
[yourview addSubview:imageView];

First try to Uninstall the app Clean the project then Install and then check if not then.
Second there may some issue with picture spelling Case senstive or Not As The iPhone is case sensitive, but the simulator is not because iPhone file system is case sensitive and Mac OS is not
Third
Add a break point where you add UIImage
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 50)];
imgView.image = [UIImage imageNamed:#"a_image.png"];
Then on the console "po [imgView image]"
If it is nil then either the resource is not getting copied correctly into the bundle.

Related

How do I load an image into a complication programmatically iOS

I have a app which has an Apple Watch extension. I have a UIImageView in the Watch face and would like to have the image change depending on condition. I have tried this.
if ((battery > 30)&& (battery < 110) && (bat = 1)){
UIImage *lightning = [UIImage imageNamed:#"jag2#2X.png"];
[self.Jag setImage:lightning];
}
I have put the jag##2x.png in my watch asserts folder but when I call this it doesn't load no image appears. If I load it in IB it is ok any ideas?
So I got this working. I added the images to the assets.xcassett in the watch extension and then left off the #2x as Paulw11 suggested but I did need to leave the .png on to get it to work. Thanks Paul for pointing me in the correct direction.

UIImage is not displaying

I know it's a silly question. But I am not finding a way to solve this.
Image icon is located in Image assets (i.e. Assets.xcassets). It is being displayed if I run the application from Xcode (i.e. in debug mode). But it is not being displayed if I install the application from TestFlight (i.e. Release mode).
Here is my code for that.
somewhere in ViewDidLoad()
arriCon = [[NSMutableArray alloc]initWithObjects:#"home_icon",#"s_Internammatches_icon",#"InternalRating",#"s_tournaments_icon",#"s_EmailManagement_icon",#"s_Canteen_icon",#"Meeting_icon",#"s_event_icon",#"s_stats_icon",#"ic_poll",#"s_ourclub_icon",#"Album_icon",#"s_setting_icon", nil];
and somewhere in viewForHeaderInSection() (yeah, I've multiple headers in UITableView and in that, I'm displaying image)
headerView.imgiCon.image = [UIImage imageNamed:[arriCon objectAtIndex:section]];

Xcode 6: Images Not Showing Up On Device

I am creating UIImageView(s) and adding these views to a UIScrollView. The images show up when I am testing on a simulator, but when I test on an iphone 5s the images don't show up. Below is a list of things I have tried:
Clean Build
Reinstall App
Then I thought maybe it was a problem with retina images so I added retina images (the images are white pngs):
I am using the images as such:
UIButton *doneBttn = [UIButton buttonWithType:UIButtonTypeCustom];
[doneBttn setImage:[UIImage imageNamed:#"addButton.png"] forState:UIControlStateNormal];
[doneBttn setImage:[UIImage imageNamed:#"addButtonSelected.png"] forState:UIControlStateHighlighted];
[doneBttn setFrame:CGRectMake(0, 0, 50 , 30)];
[doneBttn addTarget:self action:#selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
[uiNavView addMenuBarButtonRight:doneBttn];
I know the code above works, because the image is displayed in the simulator.
What do I need to change to get the image to display on my device? Also, I have checked to make sure the files are in the xcode project directory, and not just linked.
I also faced this issue once, the cause of this issue was that I am not taking care of image name by assigning it to UIImageView, make sure that you are assigning UIImageView the exact name of the image as it is in the main bundle.
The simulator can read the image name if there is any case-sensitive issue or some extension issue like i.e. .png , .jpg, but device never reads the image name if there are issues in the naming conventions, device always treat the image name as exact.

iOS UIImage returns null

Why is this not working?
//set up check mark image
imgCheckMark = [UIImage imageNamed:#"checkmark.png"];
vImgCheckMark = [[UIImageView alloc] initWithImage:imgCheckMark];
NSLog(#"%#", imgCheckMark);
I keep getting null in the console. The image is in the bundle, I can view it in editor.
Remove the image Checkmark.png from the project
add it back and try it
Make sure that the image is in the project folder[while adding check
copy items into destination group (if needed)]
Make sure the image name is exactly the same as in the file
Check the filename for case sensitivity. If your file is Checkmark.png then it will not work properly on the device. This questions has a few more details:
Works on iPhone Simulator but not on device

Custom button not appearing on iOS device

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?
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?)
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
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:.
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

Resources