0

I have developed the IOS app, and it is my first app ever. I have 2 real devices. Iphone 5 and Iphone 6 plus.

I have created a UITable and in that under the custom cell I am showing small images let say 20 * 20 to represent something followed by its text.

For example I am using location icon and then I write its location in string. and both are horizontally aligned in a cell.

when I run it on the emulator Iphone 8, it shows the icon and the screen design is as expected. but when I run it on my both devices it is not showing me icons there it is only showing location in text form but location image is just not there in both devices.

So I know I am doing something wrong so my summed up questions are

  • What is the size should I select as image/icons like button icons ?
  • how to put images in the project? I know it is like drag and drop in assets file? but is not there a way ?
  • I am not getting on how to make image and then postfix it with @2x @3x and from which size I need to start and then How to do it ?

I followed a tutorial over youtube but that was for app icon, and my app icon are visible on each devices, and looks good. But I am really confused about other icons that I have to use inside the app. and about their sizes and about how to put them in project

Please help me, and discuss it with me instead of links of pages because I have read too much on it but still a dumb head. please help me

Android teem
  • 780
  • 2
  • 13
  • 36
  • Can you share cell constraints – Shehata Gamal Jul 11 '18 at 14:08
  • hi, it seams like you have problem with constraints of the image. Can you explain in detail how you add the image in the cell and if you ahve constarints what are they? Also if you using storyboard you can change the screen size from "view as:" button in the bottom of the view. – m1sh0 Jul 11 '18 at 14:08
  • no there is no constraint issue, can you please let me know how to put image resources in assets folder of xcode – Android teem Jul 11 '18 at 14:21

1 Answers1

2

Here is how to add an image to your project:

  1. In the Project Navigator, open the Assets.xcassets by double-clicking on it.
  2. Control-click in the blank area below AppIcon and select New Image Set from the pop-up.
  3. A new asset called Image will appear. Click on Image and give it the name you want to use, (for example "house").
  4. Drag and drop 2x and 3x PNG images into the appropriate spots. If your image is 20 x 20 points on screen, then your 2x image should be 40 x 40, and your 3x image should be 60 x 60. It is up to you to make sure those images have the proper detail and are not just scaled up low resolution images. (See Xcode images explanation for more background on 1x, 2x and 3x images).
  5. In your code, you can load the image with let image = UIImage(named: "house") and iOS will select the proper resolution image for your device. The iPhone 5 will use the 2x version, and the iPhone 6 Plus will use the 3x version.
vacawama
  • 150,663
  • 30
  • 266
  • 294
  • good explanation , but tell me you said to set image in this way , let image = UIImage(named: "house") and Ios will select correct image for me, its fine, tell me is it same if I select image for UIImage from IB. Will the IOS do the same – Android teem Jul 12 '18 at 08:02
  • 2ndly here it is my all confusions, you said If your image is 20 x 20 points on screen, but tell me how to decide , for let say I have a UIImage, and I want to set it on a left side of UiLabel. what initial size should I select for this? and also let say I have made image 16*20 (not equal in length and width ) will the 2x be the 32 * 40 ?? – Android teem Jul 12 '18 at 08:04
  • and in your example , let say I have image 20*20 and its name is house.png . so I have to make its name as house.png@2x ? postfix ?? – Android teem Jul 12 '18 at 08:05
  • 1) This works for images set for UIImage in IB as well. 2) Figuring out your images point size is up to you. Try different values until it looks right. If your point size grows due to Auto Layout on larger phones, I would put a print in the code to output the final size of the UIImageView in viewDidLayoutSubviews for the ViewController or in layoutSubviews for a custonCell and try it in the simulator for all different sized devices. Use the largest point size you see for the image as you 1x dimensions. 3) Yes, if your ImageView is 16 x 20, your 2x image will be 32 x 40, 3x will be 48 x 60 – vacawama Jul 12 '18 at 08:41
  • 4) in the old days before Apple added the Assets.xcassets catalog, you used to just dump pictures directly in a Resources directory in the project. Back then, you had to add the suffix. Now, it doesn’t matter what your images are called in Finder, because when you drag them into the 2x and 3x spots in the Assets.xcassets the images becomes a part of the image set and iOS will find them based upon the image set name. – vacawama Jul 12 '18 at 08:48
  • and you have not mentioned 4x , I think it is not yet introduced? so the maximum is 3x ?? right ? – Android teem Jul 12 '18 at 10:54
  • 1
    Right. There is no 4x. – vacawama Jul 12 '18 at 11:03
  • great and thanks , can you help me also over here https://stackoverflow.com/questions/51285220/converting-a-existing-code-into-library-ios/51286121?noredirect=1#comment89558191_51286121 – Android teem Jul 12 '18 at 11:36