Reliable iOS image flipping for RTL languages - ios

I'm trying to get image flipping to work reliably, but i'm seeing some issues. I manage my images in an Xcode asset catalog, and the ones that need to be flipped in RTL languages have been configured with the 'Direction' property set to 'Left to right, Mirrors'.
In some cases I have 2 separate assets, since flipping was not enough. Those are configured with the 'Direction' property set to 'Both' and two separate image assets are provided.
All images are PDF assets with 'Preserve vector data' enabled.
This all worked great as long as I test with iOS 11 and Xcode 9.2.
The problems start when I test on iOS 9. Images that are configured for RTL don't show up when I launch the app, even when I'm not running in a RTL language.
Since Xcode 9.3, I seem to have a new problem. The asset catalogs get updated automatically; the RTL images are reconfigured to direction 'Both' and changes are made to the json files in the catalog. Selecting 'Left to right, Mirrors' does not work anymore.
Is there anyone who has figured out how to get this to work reliably? Or am I just looking at the latest bugs in Xcode and some old issues with iOS9?
[edit]
After further analysis of the IPA file that is generated, it seems that the Assets.car file does not contain .png files for the RTL images. It seems that they are not generated (since the source files are PDF), so that would explain the missing images in iOS 9 (which does not use PDF images).

I fixed it, but it took someone at the Apple Developer Forum to point out that the asset catalog 'direction' property was not introduced until Xcode 8 / iOS 10.
This means it just doesn't work in iOS 9, and it is probably an Xcode bug that you can even select it when the deployment target is set below iOS 10.
So, don't try to use this feature when you want to be compatible with older iOS devices! You can still get it to work programatically.
If you have an image in for example a UIBarButtonItem, you can make an outlet to this button and run the following in the viewDidLoad:
self.someButton.image = [self.someButton.image imageFlippedForRightToLeftLayoutDirection];
This works because imageFlippedForRightToLeftLayoutDirection is supported by iOS 9. It only flips the image when your app is in RTL mode.
If you need to load a completely different image, you can do that as follows:
if ([UIApplication sharedApplication].userInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft) {
self.someButton.image = [UIImage imageNamed:#"someRTLImage"];
}

Related

Xamarin Image Assets for Size Classes

I am building an universal Xamarin application for iOS. I am working on the launch screen, and trying to use size classes to modify the layout for iPhone and iPad devices. The positioning works correctly, but when I try to set the image assets things go wrong.
I am trying to use the size class feature on the XCAssets file within Xcode to set the correct image I want for the different screen sizes. I have an image set for [any, any] ([,]) for the iPhone, and then I have one set for the [regular, regular] ([+, +]) for the iPad.
In Xcode's interface builder I can see the correct image in my launch xib file when switching between the [any, any] and [regular, regular] size classes. However, when I run this in my iPad simulator I do not see any images at all. Note that when I run the app in my iPhone simulator the [any, any] images are picked up correctly. It's only when running on my iPad simulator things go wrong.
I have resorted to using Xcode's tools as I cannot find a way within Xamarin to get images within a single image set for different size classes. I believe the issue I'm running into must be an issue within Xamarin not respecting the properties set in Xcode.
My question is has anyone been able to get this to work on Xamarin, and if so how?
Thanks!
Ok, so I found the solution. It appears to in fact be a bug within Xamarin and has todo with Xamarin not always updating the XIB files correctly.
Firstly, do not use the size class options inside of the XCAsset file within Xcode. Simply use the Xamarin version of the tool, and set the iPhone and iPad variations of the image set. I used the naming scheme [image_name][#2x|3x].[ext] for iPhone graphics and the scheme [image_name]~ipad[#2x|3x].[ext] for the iPad variants. However, keep in mind that according to the Apple documentation when you use size classes the ~ipad suffix is ignored. I simply use this suffix to make the file names unique between iPhone and iPad.
Second, go ahead and use size classes as you wish, but do not worry about changing the graphic name, and do not worry about the fact that you will not see an image preview when in the [regular, regular] class.
Third, before running the app use the Xamarin clean command at least once, but sometimes it takes a couple of attempts to fully clean the solution.
After theses steps the image assets worked for me for the iPad via [regular, regular] size class. I know it seems hacky, and may not be the "Xamarin" or "Apple" way of doing things, but it works.
Hope this helps someone else not spend two hours of their life dealing with Xamarin's short comings :)

XCode ios build places blue tint on images

XCode leaves a blue tint over the images in my iOS application, I have tried looking at the Debug settings, because the Apple Developer site states that CoreMotion places the overlay on the images, however, none of the settings are on in there. I have searched around for a few days before actually posting here, and at this point it is just really annoying. I thought it would be only on my test build, so I archived it and uploaded it to iTunes connect to have someone else try, with the same results, all the images were blue.
Note: This only happens when building on a device, the simulator does not exhibit this behavior.
The problem was that for some reason XCode compressing the image files mangled how the library I am using (SFML) read the file. Turning off PNG compression in settings fixed the problem.
For anyone needing this information 6 years later:
I have been using the SFML framework to try to build to multiple platforms (macOS, iOS, & Windows) within the last few days and I had this same issue with the iOS builds.
For each image that has the blue tint I had to manually go in and change the type in the File Inspector from PNG to BMP (or some other image type). Otherwise Xcode would compress the PNG and give it that blue tint.

Xcode6 image view + Asset Catalog. Image not showing

iOS Newbie here. After the announcement of Xcode 6 and SWIFT, I decided to give it a try.
Now I am three days into iOS development and found a very strange problem.
Problem: On a empty project with only 1 ImageView control, I can't figure out how to display a PNG image.
Here is what I did:
1) Create a single view project.
2) Create a Asset Catalog, add image set, add PNG image.
3) In storyboard, drag Image View Control into the board.
4) Assign image & background color to Image View
Now hit run and simulator shows only the image background but not the image.
Xcode 6, target iOS7.0, ipad 2 simulator(7.1).
Tested the same procedure in Xcode 5 and the image shows correctly. However, I wish to learn SWIFT + Xcode 6. Using Xcode 5 isn't really a solution.
Here is the project package if you care to test it.
I've had a similar problem, but for an Objective-C project. I found this "problem" listed in the release notes:
"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, but not iOS 7 and OS X 10.9."
Which I took to mean that you will not see the images if the target device/simulator is not running iOS 8. I've partially confirmed this by deleting the images from the Images.xcassets and copying them into the project as files, then they get loaded and displayed correctly.
So, I take this mean that I should avoid using the Images asset catalog for iOS 7 targets for this release and just copy the images in as files.

XCode5 won't accept all my icons and launch images

After switching to XCode5 I've just re-done all my icons and launch images for an app, with the exception of retina launch images I should have a complete set for both iPad and iPhone, iOS6 and iOS7, thanks to this tool: http://www.appiconsizes.com/
But XCode5 absolutely refuses to use them all. I removed all the old images from my project and added the new ones. Some, XCode automatically detects, seemingly at random. Many others, it says it can't find the images needed even though they are named according to Apple's guidelines (as far as I can see, it's all a bit confusing with so many variants). It lets me find them manually but doesn't seem to be using them properly.
And my launch images, it insists on using images from a different target even though these are definitely not marked to be included in this target. It won't even let me change those ones, if I try to then it just ignores my selection.
A few screenshots follow. I originally had just an "Icon" icon identifier in my plist, since Apple say it will automatically detect different variants, but XCode has then added Icon-76 and Icon-120, seemingly contradicting this. I'm aware XCode5 supports controlling things more through your plist than XCode4, but shouldn't require that - you should be able to tell it the icon base name or use "default" and it would figure things out?
Use an asset catalog for your project.
It has placeholders for the launch image and the icon and each one tells you which size it needs.
Much easier than handling lots of dirrefent files in different locations.
In the project info page there is a button that says "use asset catalog". It will import all your images for you. The code doesn't change when using an asset catalog so it will all still work.
Another thing with asset catalog is that the name of the files doesn't matter. You just drag the image to the slot you want it to go into. With icons and stuff there is only a size restriction.
Even for retina images you don't need the #2x before because there is now a slot for "standard" and "retina" images.
I guess the problem is in Your icon Name,
for iPhone retina Name should be Icon-60.png , Icon-60#2x.png
So as Fogmeister suggested use asset catalog
Like
So its like

Settings the splash screen in one resolution causes the others to disappear in xcode

I am trying to setup the splash screens at multiple resolutions in the new XCode 5.0 but every time I import one image resolution (at the exact size), the previous imported image is removed from the list...
Any work around to this strange behaviour? (bug?)
Are you using the assets catalog feature of Xcode 5? If not, you should. You specify in your target settings to use the entry in the asset catalog, and you just drag and drop the different launch images. It's really easy.

Resources