0

I have static cells in a tableview. In them I have one image view that is left size and one label right side. I have also used auto layout. My problem is:

The image size looks the same for all devices. That means if the image size is 50 X 50 for iphone 5s then for iphone 6plus it should appear 100 X 100. But it shows only 50 X 50.

demongolem
  • 9,474
  • 36
  • 90
  • 105
John
  • 238
  • 2
  • 11
  • if done correctly a 50px image is going to show as 50 px in all iphones. The quality will increase to match the iPhone quality but the image sizes still should be the same (assuming I understand you correctly) – logixologist Apr 20 '17 at 13:36
  • One option is that only set trailing & leading and top & bottom edge constraint in your cell. – Gagan_iOS Apr 20 '17 at 13:39
  • did you add images in assets folder ? or did you set height and width constraints to imageview ? – KKRocks Apr 20 '17 at 13:42

2 Answers2

1

What constraints are you using within that cell? If you re using a height constraint of 50 your image will always be 50.

You might want the image to be a specific size for each device (i.e 50,70 and 100 correspondingly). A way to go about this is make the image have a distance from the top, bottom and left side of the cell and give it a specific aspect ratio.

Then use the tableView delegate method to determine the size of your cell.

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

//if iphone 5 return x (e.g 50)
//if iphone 6 plus return y (e.g 100)

}

This way you re changing your cell size ( which im guessing you need to be smaller if your image is smaller and bigger if your image is bigger ) and your image auto resizes automatically using the constraints mentioned above

Return-1
  • 2,329
  • 3
  • 21
  • 56
  • This is the closest answer. Using autolayout to set top, bottom, trailing, and leading constraints, and then the ^tableView.heightForRow delegate method will allow your imageView to resize according to the device that is running your application, but @Khalid Afridi 's answer also has great information on why your imageView is not resizing! – Jacob Boyd Apr 20 '17 at 14:15
1

If you set imageView size 50x50 it will show 50x50 in plus iPhones. You're think about images which has 1x, 2x, and 3x for retina screen. It will not change the Image View size it will only look good. for more information you can read this answer what is pixel and points in iPhone

but if you want to change the size of Image View in bigger devices such as iPhone plus then you have to use size class where you can configure, remove or add constraint's based on screen size or orientation

Community
  • 1
  • 1
Khalid Afridi
  • 913
  • 5
  • 12