简体   繁体   中英

Image View change size for iPhone Screen Size using AutoLayout Storyboard

I have an Image View that I want the height and width to be changed based on screen size:

  • iPhone 6 Plus 414x414
  • iPhone 6 375x375
  • iPhone 5s 320x320

Any constraints I put on the Image View in the Storyboard seem to hardcode it in (ie 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;

}

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM