最佳答案
首先将底部内容设置为这样的高度,
然后像这样设置图像约束,
然后在您的代码中执行此操作,
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let imageNew = UIImage(named: "test") //Set your image here
let oldWidth = imageNew!.size.width
let scaleFactor = tableView.frame.size.width / oldWidth
let newHeight = imageNew!.size.height * scaleFactor
let newWidth = oldWidth * scaleFactor
//Finally to get cell size just add the bottom part height for othercontents to ImageHeight here
let CellSize = CGSize(width: newWidth, height: (newHeight + 40))
return CellSize.height
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! TableViewCell
cell.NewImage.image = UIImage(named: "test")
return cell
}
关于ios - 表格 View 单元格中的 Storyboard ImageView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41179990/