简体   繁体   English

在TableViewCell中设置图像的大小

[英]Setting the size for an image in a TableViewCell

I have a table with rows of height 90. 我有一张桌子,桌子的高度为90。

I want to have an image on each row of size 50x50. 我想在尺寸为50x50的每一行上都有一张图片。

I am doing the following in cellForRowAtIndexPath : 我正在cellForRowAtIndexPath执行以下操作:

    cell.imageView.frame = CGRectMake(0, 0, 50, 50);
    cell.imageView.clipsToBounds = YES;
    cell.imageView.contentMode = UIViewContentModeScaleAspectFit;

    if (item.image){
        cell.imageView.image = [item.image smallImage];
        cell.imageView.alpha = 1.0f;
    } else {
        cell.imageView.image = [UIImage imageNamed:@"icon-greyed.png"];
        cell.imageView.alpha = 0.25f;
    }

However the images appear with height 90 (the height of the row). 但是,图像显示的高度为90(行的高度)。 What am I not doing right? 我做错了什么?

You will need to either add a UIImageView to cell.contentView which I wouldn't recommend, or create a custom UITableViewCell , which I would recommend. 您将需要将UIImageView添加到不推荐使用的cell.contentView中,或者创建一个自定义UITableViewCell推荐使用的cell.contentView Then you can add a UIImageView to your custom cell and resize it to the dimensions you require. 然后,您可以将UIImageView添加到您的自定义单元中,然后将其调整为所需的尺寸。

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

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