1

我正在创建一个缩略图网格,使用一个 UITableView,每个单元格显示 3。在这个阶段,我只是试图放置 3 个静态图像以获得正确的位置/大小。但我无法控制缩略图的位置和大小。这是我的一张缩略图的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// after getting cell..

UIImage *image = [UIImage imageNamed:@"placeholder.png"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50.0, 0.0, 85.0, 85.0)];
imageView = [[UIImageView alloc] initWithImage:image];        
[cell addSubview:imageView];

return cell;

}

我的理解是否正确,我通过在 UIImageView 中设置图像来控制图像的位置和大小?

我很感激帮助。

4

1 回答 1

4

您需要在视图中缩放图像:

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[imageView setFrame:CGRectMake(50.0, 0.0, 85.0, 85.0)];
[imageView setContentMode:UIViewContentModeScaleAspectFill];
[cell addSubview:imageView];
于 2012-04-15T04:52:59.983 回答