TableCell中的UIImageVIew显示的不是正确的SIze

时间:2014-01-31 09:38:01

标签: ios objective-c uiimageview interface-builder

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

enter image description here

我希望Cell对TableView(蓝色边框)有一点空间,所以我在Cell中加了一个额外的View。正如您所看到的,UIImageVIew实际上很小并且不高于两个标签,但是当我在设备上运行我的代码时,UIImageView作为白色View高,甚至覆盖了Label一点点。我在我的代码中唯一做的就是:

- (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"]];
.
.
.

出了什么问题?

3 个答案:

答案 0 :(得分:1)

这将解决您的问题

eventCell.imageView.contentMode = UIViewContentModeScaleAspectFit;

答案 1 :(得分:0)

我希望您没有错过自定义单元格内对象的自动布局约束。

如果没有,请选择标签/视图  在工具栏编辑器>解决自动布局问题>添加缺少的约束

并根据需要更改自动布局约束。

答案 2 :(得分:0)

我认为您应该在右侧面板中更改您的属性。

您还可以停用自动布局约束,并将您的商品放在好位置,然后以编程方式设置它们。

示例: 位于文件顶部:

#define X_Cell_Padding 10
#define Y_Cell_Padding 10
在cellForRow方法中

 [[cell yourImageView] setFrame : CGRectMake(X_Cell_Padding, Y_Cell_Padding, yourImageView.frame.size.width, yourImageView.frame.size.height)];

不要忘记使用您的IBOutlet yourImageView创建自定义单元格类,并为storyboard / xib中的单元格设置此类

相关问题