Reputation: 3154
I have an Image View
that I want the height and width to be changed based on screen size:
Any constraints I put on the Image View
in the Storyboard seem to hardcode it in (i.e. constrain height and width), so it'll work for one size but not all the others.
Help would be appreciated, thanks!
UPDATE
I've got a custom table view cell TableViewCellTwo
, and it sits inside of the table view controller TableViewController
.
TableViewController.m
TableViewCellTwo *api2Cell = [tableView dequeueReusableCellWithIdentifier:@"YourAPI2Cell"];
api2Cell.labelHeadline.text = user;
api2Cell.labelDescription.text = cap;
api2Cell.labelPublished.text = date;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 600.0;
// SDWebImage
if ([data.images count] == 0) {
NSLog(@"Images Count: %lu", (unsigned long)data.images.count);
}
else {
Images *imageLocal = [data.images objectAtIndex:0];
StandardResolution *standardResolutionLocal = [imageLocal.standard_resolution objectAtIndex:0];
NSString *imageURL = [NSString stringWithFormat:@"%@", standardResolutionLocal.url];
__weak TableViewCellTwo *wcell = api2Cell;
[wcell.imageView
sd_setImageWithURL:[NSURL URLWithString:imageURL]
placeholderImage:[UIImage imageNamed:@"320x180.gif"]
];
}
return api2Cell;
}
Upvotes: 1
Views: 4400
Reputation: 104092
What you want is to have your image view pinned to the two sides of the view (with 0 length constraints), and give it an aspect ratio of 1:1. If you do that, plus add a vertical constraint to the label above it, then it will work properly (there should be no constraint to the bottom of the view).
Upvotes: 3