ios - TableCell 中的 UIImageVIew 显示的大小不正确

标签 ios objective-c uiimageview interface-builder

我有一些奇怪的问题。我使用 Interface Builder 创建一个具有三个标签和一个 UIImageView 的自定义 TableCell:

enter image description here

我希望单元格与 TableView(蓝色边框)有一点空间,所以我在单元格内放置了一个额外的 View 。如您所见,UIImageVIew 非常小,不超过两个标签,但是当我在设备上运行我的代码时,UIImageView 与白色 View 一样高,甚至稍微覆盖了标签。我在代码中所做的唯一事情是:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
static NSString *CellIdentifier1 = @"CustomCellReuseID";

GTEventCustomCell *eventCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (eventCell == nil) {
    eventCell = [[GTEventCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
}

// Configure the cell...
[eventCell.imageView setImage:[UIImage imageNamed:@"heart.png"]];
.
.
.

怎么了?

最佳答案

这将解决您的问题:

eventCell.imageView.contentMode = UIViewContentModeScaleAspectFit;

关于ios - TableCell 中的 UIImageVIew 显示的大小不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21476677/

相关文章:

ios - 如何使用复合 NSPredicate?

objective-c - 视频不播放 ios 6

ios - Touchesbegan 和 touchesmoved 函数不适用于 UIImageView

ios - 如何在 Xcode 中更新 Firebase SDK

ios - 使用 NSDictionaries 的 NSMutableArray 对 UITableView 进行分段

ios - 为什么在检索 json 数据和显示 viewcontroller 之间有很长的延迟

objective-c - null,nill是Objective-C中的字符串类型

ios - 从 xcode 中删除旧的/未使用的配置文件

ios - 如何以编程方式将 ImageView 与 ScrollView 的底部对齐?

ios - UIImageView 中心未正确更新