简体   繁体   English

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

[英]UIImageVIew in TableCell shows not the correct SIze

i have some strange Problem. 我有一些奇怪的问题。 I use the Interface Builder to create a Custom TableCell with three Labels and one UIImageView: 我使用界面生成器创建具有三个标签和一个UIImageView的自定义TableCell:

在此处输入图片说明

I want that the Cell has a little space to the TableView (the blue border), so i put an extra View inside the Cell. 我希望Cell到TableView留一点空间(蓝色边框),所以我在Cell内放了一个额外的View。 As you can see the UIImageVIew is realy small and not higher than two labels, but when i run my code on the device the UIImageView is high as the white View and even covers the Label a little bit. 如您所见,UIImageVIew非常小,并且不超过两个标签,但是当我在设备上运行代码时,UIImageView与白色View一样高,甚至覆盖了Label一点点。 The only thing i do in my Code is: 我在代码中所做的唯一一件事是:

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

What´s wrong? 怎么了?

这将解决您的问题

eventCell.imageView.contentMode = UIViewContentModeScaleAspectFit;

I hope you have not missed the auto layout constraints for the objects inside the custom cell. 希望您不要错过自定义单元格内对象的自动布局约束。

If not select a label/view in toolbar Editor > Resolve Auto Layout issues > add missing constraints 如果没有,请在工具栏的“编辑器”>“解决自动布局问题”中添加标签/视图,然后添加缺少的约束

and change the auto layout constraint as you need it. 并根据需要更改自动布局约束。

I just think you should change your properties in the right panel. 我只是认为您应该在右侧面板中更改属性。

You can also desactivate autolayout constraints and, to be sur to place your items at the good place, set them programmatically. 您还可以取消激活自动布局约束,并且要以编程方式设置它们,以便将其放置在合适的位置。

example : at the top of your file : 示例:在文件顶部:

#define X_Cell_Padding 10
#define Y_Cell_Padding 10

in cellForRow methods : 在cellForRow方法中:

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

don't forget to create a custom cell class with your IBOutlet yourImageView and to set this class for the cell in your storyboard / xib 不要忘记使用IBOutlet yourImageView创建自定义单元格类,并在情节提要/ xib中为该单元格设置此类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM