调整cell.UIImageView.image的大小

2023-12-08

我也有不同尺寸的不同图像,我想将其放在每个单元格中的 cell.imageView.image 中,但我想在每个单元格中制作相同的尺寸,尽管图像具有不同的尺寸,我在我的代码中写下这一点:

UIImage *image = [UIImage imageNamed:imageName];
    cell.imageView.image = image;
    cell.imageView.layer.masksToBounds = YES;
    cell.imageView.layer.cornerRadius = 5.0;

    float sw=image.size.width/cell.imageView.image.size.width;
    float sh=image.size.height/cell.imageView.image.size.height;
    cell.imageView.transform=CGAffineTransformMakeScale(sw, sh);

but it doesn't work, i'am sure that's right.. any body can help me.??alt text


我刚刚遇到了同样的问题。我希望照片的尺寸为 65 x 65,但它们却填充了 UITableViewCell 的大小。我通过以编程方式创建 UIImageView 并将其作为子视图添加到 UITableViewCell 来解决它。例如:

UIImageView *imageView = [[UIImageView alloc] initWithImage:photo];
imageView.frame = CGRectMake(6.5, 6.5, 65., 65.);
[cell addSubview:imageView];

为了清楚起见进行编辑:当我尝试在 Interface Builder 中创建 UIImageView 时,发生了此问题。我将其从 Interface Builder 中取出并以编程方式添加。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

调整cell.UIImageView.image的大小 的相关文章

随机推荐