In iOS I'm developing a game(Universal), So at the runtime images are available on server and I'm going to download them. So what I should do?
I can download any image #1x, #2x and #3x. But in this case my every image going to have 2 versions so it will take too much space on server.
or
Should I keep #3x image only on server and I resize it to #1x or #2x according to device scale.
Which should be preferred.Thanks.
Now apple introduced new concept of app-thinning. You don't have to worry about putting multiple images inside bundle. You add all images 1x, 2x and 3x within the application assets. Based on device type App Store will provide images required to run on the application.
Related
I've started developing an iOS app, adding pictures in resolution which is ok for standard retina screens. Now I want to add #3x pictures for iphone 6 plus and 7 plus. I don't want to include 1x version for older devices. I've renamed all image files to name#2x but these are not recognized in the project anymore. I was thinking that #2x name modifier will be ignored, but this is not the case. Do I need to explicitely add "#2x" in all places I'm referencing these pictures in the code? Or should I leave standard retina versions without any name change and these will be used anyway as #2x and only use #3x name modifier for higher resolution versions?
Use asset catalogs. See Apple Documentation
Then it's really easy to define 1x, 2x and 3x images by drag&drop. If you load the image in code by name (without scale) it works like a charm. If 1x is missing the next possible image will be used automatically.
You can import pdf-images or well known as vector-images as single vector in assets.Hence No need of 1x,2x,3x seperatly.
You can use Blade
Better asset workflow for iOS developers. Generate Xcode image catalogs for iOS / OSX app icons, universal images, and more.
with a definition file like this will generate all the images for you and put it in the right place
blades:
- source: store/slice1.png # this image should be the only image, and the biggest image you can use (typically for icons, 1024x1024)
mount: Project/Assets.xcassets/AppIcon.appiconset
I recently asked a question about why we use the 3 different image types listed above, and got good/detailed responses. It also lead me to question something else...
Assume I am working in XCode (with SWIFT) and have the three image sizes #1x, #2x, #3x for a particular say UIImage on an iPhone. Now, I want it to look nice on iPad, so I add some scaling. However, this will change the sizes of the 1x, 2x, 3x images I need for the iPad, so I need to make 3 more to compensate for that new size. Now how will XCode differentiate between the two? Do I need to check what size screen I am using and then choose the images?
I read that assets could help me, but that only deals with iPhone vs. iPad, what if I scale my images across iPhone 4, 5, 6 and iPad. That's a lot of different sizes and #x images, and I read Apple doesn't like device checking so I'm not sure how that would happen.
I hope this makes sense. I get the #1x, 2x, 3x per device, but if my app is being designed for universal device use, then how do I manage all of these different sizes in code for the proper device?
You really should use image asset catalog. It makes it almost too easy. Here is the definition Apple gives so you know it's not hearsay:
Image sets: Used for most types of images, an image set contains all the versions, or representations, of an image that are necessary to support various devices and scale factors.
And it goes on further:
Each set in an asset catalog has a name. You can use that name to programmatically load any individual image contained in the set. To load an image, call the platform specific class method, passing in the name of the set that contains the image. The OS will load the image from the set that is most appropriate for the current scale factor
So there really is not much for you to do. I don't know where you heard the opposite
See Documentation here
You need to check the size of the biggest image, if you are using an iPad figure out the size of the UIImageView frame. For instance if it is 400*400pts then your image will be 1200*1200. Just use a single image. I don't think you need to include the #2x and #1x. The 1200*1200 covers your bases for the largest possible image and scaling down will still have plenty of pixels left over for the full #3x resolution on other devices and so on. This is how I understand it anyway. I also wondered this myself and only found #1x #2x #3x useful for things that I didn't scale up as the screen size increased such as some buttons.
I have some image resources, such as toolbar-1#2x.png toolbar-2#2x.png toolbar-1#3x.png toolbar-2#3x.png, I find that the 3x images can't autosize for iPhone 6/6plus, how can I set the 3x size images for iPhone 6/6plus? thanks.
Just drag your images to your xcassets file in your project. Xcode handles all the sizing stuff.
Not really directly relevant but as a known issue, you cannot use jpg files in your xcassets file on iOS7.
I hope you know what is Images.xcassets , you should use asset catalog for adding all your 1x,2x and 3x images.
As per apple doc:-
An asset catalog can include:
Image sets: Used for most types of images, an image set contains all the versions, or representations, of an image that are necessary
to support various devices and scale factors.
App icons: App icon sets contain all the representations of the icon that iOS apps must provide to be displayed on a device’s Home
screen and in the App Store.
Launch images: Launch image sets contain all the representations of the static launch image that iOS apps must provide to be
temporarily displayed when the app is launched.
With the need of 3x images in iOS 8 I figured it would be easier to manage images with an asset catalog in Xcode 6. I am trying to just provide a single image, the 3x scaled image to the asset catalog and I want Xcode to automatically downscale that image to generate 2x and 1x versions of the 3x image, so that I don't have to do it manually.
Right now this is what I have:
I really hope that Xcode has such a feature to automatically create 2x and 1x images and I just have not discovered it yet. If there isn't any such feature, are there any alternatives? (I know IconKit but it is annoying and hasn't been updated to support 3x images. If it was made properly in the first place it wouldn't even need an update..)
I know that Xcode automatically can generate all images from a vector pdf, but thats not what I am looking for!
I ended up making a small mac app that takes care of the dirty work. You can drag and drop one or multiple .jpg or .png files into the app's main view; it will detect the input image's scale and create the smaller scaled images. With this app I only need to create a single, 3x image and drag it into the app to create the two smaller images. It saves so much work!
The source can be found on my GitHub page, simply download it and run it on your mac! https://github.com/JonasGessner/ImageReducer
There is another way to solve this problem.
Use Automator to create Mac OS X service which create #3x, #2x and normal image on base of 1 image in #3x resolution automatically. It use just 3 methods: duplicate images, scale down, and rename.
Ready Mac OS X service made in Automator you can find here:
https://github.com/lukszar/iOS-Images-Prepare
late to the party but there is one tool which make all assets #1x, #2x, #3x and icons for you in just one click. And also export to XCAssets file.
You can find it here: https://github.com/angelvasa/AVXCAssets-Generator
Hope this will help someone
If you do not provide 1x or 2x assets, and your app is run on a 1x or 2x device, it should downsample the 3x asset at runtime. This may look fine, but depending on the scaling method used, it may also look really bad, so make sure this is really what you want.
If a folder named *.imageset, and the contents in it is well organized, Xcode will actually recognize them as an image. So this is another way to do this: https://github.com/albert-zhang/gen_xcassets
This python script will quickly auto generate #2x version for all images in a folder.
I have made an iPad app and it works cool. Problem is that my client want's to have retina high resolutions also supported in the app. So lets say We are using images with normal resolution in the app are of 15mb , so again we need to add high resolution each file. So it will increase the file. Is there any way where we can just place high res files only and they should work on both retina and non-retina .
You can fetch image asset using [UIImage imageWithName] in that case, at the runtime appropriate image will be fetched for the device, i.e. if you'll use non-retina device it'll take 1x images and if you use retina device it'll use 2x images.
But, if you want you can fetch the file with [UIImage imageWithContentsOfFile:] you'll be able to fetch that particular file.
You can also use ImageOptim tool to optimse the image without image quality loss.