如何根据屏幕大小设置UITableViewCell高度

igr*_*rik 6 objective-c uitableview ios

我从网上下载数据,它由文字和图片组成.我将这些数据放入UITableView,我希望图像成为UITableViewCell的背景.所有图像具有相同的分辨率620x350.

所有的iPhone都有不同的屏幕尺寸,因此我需要根据屏幕尺寸缩放图像的宽度和高度,并对UITableViewCell执行此操作.

什么是最好的解决方案?

谢谢.

Ben*_*nie 2

只需使用- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  CGFloat aspectRatio = 350.0f/620.0f;
   return aspectRatio * [UIScreen mainScreen].bounds.size.width;// assuming that the image will stretch across the width of the screen
}
Run Code Online (Sandbox Code Playgroud)