0

Scenario:

I have a custom UITableViewCell, and i have added a UIImageView inside it. I can add width, height, top, bottom, trailing, leading, center vertically/horizontally constraints to it, but i want to add constraint for aspect ratio. Storyboard doesn't let me add constraint for aspect ratio with Content View of UITableViewCell, so to overcome it i added another view with constraints top, bottom, trailing, leading (constant = 0) and then made UIImageView a subview of it and added aspect ratio constraint. After that i mentioned height of the cell using

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60; // for example
}

This works fine.

Question: Is this the good approach or there is another way to address same Scenario?

P.S : I would have added screenshots but forum is not letting me

Zarar
  • 41
  • 7
  • If you don't want your image to scale then just fix it's width and height and use single constraints horizontally and vertically.. means if you want it center don't use leading or trailing vice versa.. and same for vertically – Asadullah Ali Apr 16 '15 at 14:47
  • i want my image to scale that is why i want to add proportional height/width constraints to its superview – Zarar Apr 16 '15 at 17:15

0 Answers0