【发布时间】:2018-08-20 06:22:19
【问题描述】:
在 iOS 应用程序中,我有一个 UICollectionView 显示图片网格。但是我无法精确设置每个 UICollectionViewCell 中包含的 UIImageView 的大小。所有都在 Interface Builder 中定义。
正如我们在下图中看到的,不仅每张图片的大小不一样(代码显示它应该对所有人都固定),而且它们与我的 setFrame 值不匹配。 尝试应用其他帖子的建议,但问题保持不变。
如何为 UIImageView 设置固定大小?
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"backgroundCell" forIndexPath:indexPath];
UIImageView *imageView = (UIImageView *)[cell viewWithTag:110];
imageView.image=[UIImage imageNamed:[allImages objectAtIndex:indexPath.row]];
imageView.translatesAutoresizingMaskIntoConstraints=YES;
imageView.frame=CGRectMake(10,10, 50, 200);
cell.backgroundColor=[UIColor redColor];
return cell;
}
【问题讨论】:
标签: ios objective-c uicollectionview uiimageview