Images not showing in iOS 7.1 with XCode 6 / Swift - xcode

I have this ObjC code:
[self.myButton setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:#"%#-button", self.myObject.name]]
forState:UIControlStateNormal];
This works great with these combinations:
XCode 5, iOS 7.1
XCode 6, iOS 7.1
XCode 6, iOS 8
But when I port one single class of the project to Swift -- a class which is unrelated to anything that is happening in this code -- the images do not display in XCode 6 for iOS 7.1. It does work with XCode 6 and iOS 8.
I finished porting the entire project to Swift, so now the code looks like:
self.myButton.setBackgroundImage(
UIImage(named:self.myObject.name + "-button"),
forState: UIControlState.Normal
)
And it's still unhappy on iOS 7.1. Still no images. (The custom icon works, though.) Yes, I know this is just beta software, and it's probably just a bug ... ? But I'm just wondering if anyone has a solution or insight.
I only started using XCode and ObjC about a week ago (surprise! ObjC is now deprecated!), so it could be that I am missing something, but since it works in ObjC, and in Swift+iOS8, it seems like it's probably a bug.

I've managed to overcome this by not using Asset Libraries to store my images.
Add your images to the project using the "old style naming", like Image.png and Image#2x.png, then load them without any extensions in the filename, as such:
let myImage = UIImage(named:"Image")

Fixed in XCode 6 beta 2
Images from asset catalogs in projects with a minimum deployment target of iOS 7 or OS X
10.9 will be available when running on iOS 8 and OS X 10.10, and now also iOS 7 and OS X
10.9. (17029658)
release xcode 6 beta 2 notes

For me it was because I suddenly add jpg image to Image Assets. Just resaved it as png and all work well

I guess you are testing it on simulator. Make sure the desired image is copied to 7.1 bundle. To do it check copy resources bundle build stage or check manually app bundles for different simulators at ~/Library/Application Support/iPhone Simulator/.

#o KB o points out here that the Xcode6 Beta release notes mention that xcassets bundles aren't supported for iOS7. Additionally, I've found it surprisingly hard to get rid of asset bundles in your project. This can cause naming collisions if your images have the same name as images that were previously in the bundle (you probably want the same names, so you don't have to rename your images everywhere in code / IB).
Here's a workaround:
Copy each image out of your .xcassets image bundle to a new directory (let's call it Images/). See below for a script to make this easier.
Delete your .xcassets bundle. (surprisingly, removing it from the project isn't enough. In my testing, if the .xcassets bundle was anywhere in the same directory as the Xcode project or related sources, it would get copied in. Alternately, you can remove the .xcassets extension)
Add all your image files to your Xcode project
Clean (cmd + shift + k)
Delete the app from the target device or simulator
Install and run
To make step #1 less tedious, I wrote a script to copy images out of the .xcassets bundle and into a directory of your choice: https://github.com/johnboiles/xcasset_exporter
mkdir Images
./xcasset_exporter.py MyProject/Images.xcassets Images

I had a problem where some images in xcassets worked and others didn't (only for iOS 7.1).
I solved it by deleting the problematic image sets and creating new ones with different names.

If you are attempting to use an external bundle with proper PNG images stored in either an "old style" folder or inside xcassets then apps running on iOS 7 will not be able to access these images.
I tried a suggestion from another answer here to add the "old style" folder path of the images in the external bundle but that didn't work for me. My solution, which fit my scenario, was to expose an outlet for the resource in the nib inside the external bundle. This allowed the main app to set with an accessible image to it. Whether this is a bug or simply a constraint in using nibs contained in external bundles with iOS 7 will matter less as it rides on to the usage sunset...
PS: Apps running on iOS 8 where able to access images in the external bundle xcassets just fine so choose your poison for supporting iOS 7.

Related

How to display images in Muti-Platform Xamarin.Forms Project on iOS

I've got a Xamarin.Forms Project containing an Android and an iOS Platform Project.
I've got my whole application working on Android and I am now struggling on the iOS part. I can't get my images to display on iOS.
I've followed the Microsoft guide on how to work with images on Xamarin.iOS, but it's simply not working.
I have created a minimum example from a new project and uploaded it to GitHub, it can be found here.
Output: On Android, the image is being displayed fine, on iOS, the screen stays empty. In addition to that, the logs I've added to AppDelegate.cs show, that the images cannot be found by using UIImage.FromBundle()
I've also checked the CSProject file of the iOS project, but it already contains the <ImageAsset> item groups.
I am on Visual Studio Professional 2022 (Windows) Version 17.4.1
Can someone please have a look into this? I am going crazy...
I have test your project with the Visual Studio 2022 for mac. And I had the same results in the Android platform and ios platform. The small car icon will show at the top of the screen.
But for the iphone 14 pro simulator, which has a notch screen. The car icon almost be covered. So you can try to run it on the ipad or a device without notch screen to check the car icon will show or not.
In addition, I have checked your Assets.xcassets folder and the official sample on the github. There is no a such xxx_vector folder in it.
Background information:
What's deprecated (but still works) is individual resource files (aaa.png, aaa#x2.png), with no xcasset.
An xcasset containing those files is not deprecated. Nor is it likely to become deprecated in the future.
If you still want to test with .pdf containing vectors:
What is problematic about your setup is that you have TWO representations of car_settings. One with .pngs, one with vector pdf.
What happens if you remove the xcasset with .pngs, and rename the one with pdf to match the filename in it? (car_settings xcasset, with car_settings.pdf).
Close VS, and delete all .bin and .obj folders after making this change, to ensure VS correctly rebuilds with the vector version.
If this still fails, then you likely have encountered a bug. Add as an issue at github xamarin forms issues. Be sure to mention the versions of VS and Xamarin.Forms that has the problem.

Image from asset catalog not accessible

In my project I have multiple asset catalogs, one of which is named images.xcassets.
I am able to access all the images inside said asset catalog using either UIImage(named: "image.png") or #imageLiteral(resourceName: "image.png") (with and without the file extension .png).
Issue
Now, trying to access resource image2.png works just fine with the iOS 11.2 iPad 10.5" simulator. However, the exact same build crashes when using the iOS 11.2 iPad 12.9" (2nd gen.) simulator with the following "message":
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
This issue has just emerged, I was always able to access the image before today. I have not touched a thing...
What I've tried
target membership set to project's target
removed the asset catalog from Copy Bundle Resources in Build Phases
cleaned and rebuilt the project
deleted image2.png from the catalog and added it back
deleted the whole asset catalog and added it back
deleted the app from the 12.9" simulator and re-installed it
quit & re-opened Xcode and the simulator
Any idea why this specific resource can't be accessed anymore?
Notes:
so far, I didn't run into this error using real devices (tested with iPad Air 2 & iPad Pro 1st Gen.)
Has to do with the color space apparently.
I was able to "save for web" in Photoshop and convert the image to sRGB for an image file that doesn't crash in the iPad Pro 12.9" 2nd generation simulator.

Xcode icon / launch screen catalogs with empty images

I have an old project (xcode 6) which is using icons and launch images by naming (placed in the root folder and added them through the info.plist).
The thing is, I would like to start using xcode catalogs for icons and launch images but I realized I don't have many of the assets they are requesting in those catalogs.
I was thinking in just filling the ones I have, but I'm afraid Apple will reject my version once I upload it to the itunes. Anyone knows if you can just leave empty images?
Use this - "Migrating Your Images to an Asset Catalog" Xcode will give you warning for all missing icons based on your deployment target
https://developer.apple.com/library/mac/documentation/IDEs/Conceptual/AppDistributionGuide/ConfiguringYourApp/ConfiguringYourApp.html#//apple_ref/doc/uid/TP40012582-CH28-SW5

Xcode 6 loads 3x image incorrectly when app's Deployment Target is set to 6.0 or 6.1

I get this issue when building UI in storyboard (or xib) in xcode's interface builder. After I assign the image (with the same name in asset catalog) to an image view in Interface Builder, the xcode loads 3x image file instead of 2x in any non-retinahd devices which is running ios8.
Note that this bug only happens when app's deployment target is set to 6.0 or 6.1.
I'm using asset catalog to manage image resources.
This issue is tested and happens both in Xcode 6.0.1 and 6.1 GM seed 2.
I googled the issue and could rarely find the related topic. So I wonder if any one gets the same issue with me and what is the best workaround for it. Thank you.
The following is the steps to reproduce this issue in case anyone has the interest:
Install Xcode 6
Create an iOS project and set to use objective-c as project language.
Change the app's deployment target to 6.0 or 6.1.
Add 1x, 2x and 3x version of an image to the asset catalog.
In interface builder, add a UIImageView to the default view controller's view of default storyboard.
In interface builder, set the image's name as the same image name added in step 4 in asset catalog.
Select the simulator as iPhone6 (or any simulator runs on iOS 8.0 except iPhone6 Plus).
Clean the project (Product/Clean).
Run the project.
UPDATE:
As #Andrei Mankevich mentioned in the comment, this bug seems to be fixed in iOS 8.1.
And I have confirmed it using the simulator running iOS 8.1 in Xcode 6.1 GM seed 2(sorry I don't have a real device running iOS 8.1 currently).
So as #Andrei Mankevich pointed out, this bug might only exist in iOS 8.0.x.
After some research it looks like this issue is related to iOS indeed and so it isn't likely to be fixed by upcoming Xcode update. That's what documentation says about Asset Catalog:
For projects with a deployment target of at least iOS 7 or OS X 10.9, Xcode compiles your asset catalogs into a runtime binary file format that reduces the download time for your app.
So when we use deployment target 6.0 resources are just stored in different way inside IPA file. While iOS 8.0 is loading compiled resouces correctly, it has the issue with loading non-compiled resources and always loads 3x density images. And this issue was already fixed in iOS 8.1.
As for possible workaround in our app we fixed it by setting exact size of each element in xib and using UIViewContentModeScaleAspectFit value for contentMode flag . We use the same image resources with just different resolution so after scale they also look the same. But of course it should have negative impact on performance.

Converting iPhone XIB to iPad version with Xcode 4

With Xcode 3 in Interface Builder you were able to upscale an iPhone XIB file to an iPad version. However in XCode 4 I cannot find a way to do this. I would really prefer not to have to create the XIB again from scratch. Is there a way to do this like there was in Xcode 3?
This has been asked a few times, and unfortunately it seems (or rather, it's sure) that the option (Create iPad Version Using Autosizing Masks) has been removed from Xcode 4.
You will need to copy/paste the UI elements, and re-link them to your code.
OR: You are now allowed to install both Xcode 3 & 4 (simply choose a different folder to install it to). Since the nib files' format did not change, you can upgrade them in Xcode 3, and copy the converted files back into Xcode 4.

Resources