Ios 如何根据图像的大小调整图像视图的大小?

Ios 如何根据图像的大小调整图像视图的大小?,ios,objective-c,uiimageview,uiimage,Ios,Objective C,Uiimageview,Uiimage,我正在从Parse加载图像,并将图像加载到UITableViewCell中,我希望根据检索到的图像大小调整图像视图的大小。我该怎么做?如果你需要一个例子,我认为instagram有不同大小的图像视图 请检查此链接。。这可能对你有帮助 您可以使用自定义UITableViewCell调整图像视图的大小,如果您想实现自定义单元格,我可以共享示例代码 为CustomCell创建新的Nib,并为UILabel(如果需要)和UIImageView添加IBOutlet @interface CustomTab

我正在从Parse加载图像,并将图像加载到UITableViewCell中,我希望根据检索到的图像大小调整图像视图的大小。我该怎么做?如果你需要一个例子,我认为instagram有不同大小的图像视图

请检查此链接。。这可能对你有帮助


您可以使用自定义
UITableViewCell调整图像视图的大小,如果您想实现自定义单元格,我可以共享示例代码

CustomCell
创建新的Nib,并为
UILabel
(如果需要)和
UIImageView
添加
IBOutlet

@interface CustomTableViewCell : UITableViewCell
@property (nonatomic, retain) IBOutlet UILabel *nameLabel;
@property (nonatomic, retain) IBOutlet UIImageView *thumbnailImageView;
@end  
然后在返回单元格的类中,执行以下使用自定义单元格的实现

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * simpleTableIdentifier = @"CustomTableViewCell";

    CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    cell.nameLabel.text = @"If you want to set any text";
    [cell.thumbnailImageView setImage:[UIImage imageNamed:@"Replace Image Name"]];
    cell.thumbnailImageView.frame = CustomFrameYouWantToSet;
    return cell;
}  
您还可以参考以下教程来实现自定义TableViewCell。

您可以根据图像的大小,以编程方式更新UIImageView的自动布局约束或以编程方式创建UIImageView(添加为子视图)。@farhan我已经编辑了我的答案,希望能对您有所帮助。