【发布时间】:2015-09-08 10:30:16
【问题描述】:
我有一个表格视图,其中每个单元格都有一个图像。
图片来自不同的尺寸。所以当我制作一个单元格时,我必须给 UIImageView 一个宽度和高度的约束。
现在我想要的是:当图像加载到单元格的 UIImageView 中时,UIImageView 的大小应该根据图像本身进行调整。
我在过去 2 天进行了试验,但无法修复它。由于限制,表格中的单元格一直有空格。
我用来填充单元格的代码:
class ProductTableViewCell: UITableViewCell {
@IBOutlet weak var productImageView: UIImageView!
@IBOutlet weak var productTitleLabel: UILabel!
@IBOutlet weak var productDescriptionLabel: UILabel!
var orgframe = UIImageView()
func configureCellWith(product: Product){
orgframe.frame.size = CGSizeMake(400, 600)
productImageView.image = product.image
productDescriptionLabel.text = product.description
productTitleLabel.text = product.title
var urlstring = product.imageURL
ImageLoader.sharedLoader.imageForUrl(urlstring as String, completionHandler:{(image: UIImage?, url: String) in
//self.productImageView.frame.size = (image?.size)!
self.productImageView.image = image!
})
}
}
UIImageview 的约束:
【问题讨论】:
标签: xcode swift uitableview tableview tableviewcell