我已设法更改单元格的行高,但现在用作图标的图像保持相同的大小,但现在太小了。我希望它的尺寸为 72x72,粘在单元格的左侧。
我在cellForRowAtIndexPath
中使用以下内容:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = cellForTableView(tableView)
let checklist = dataModel.lists[indexPath.row]
cell.textLabel?.textColor = UIColor(red: 25.0/255.0, green: 25.0/255.0, blue: 112.0/255.0, alpha: 1.0)
cell.textLabel?.font = font
cell.textLabel!.text = checklist.name
cell.textLabel?.adjustsFontSizeToFitWidth = true
cell.textLabel?.textAlignment = NSTextAlignment.Left
cell.accessoryType = .DetailDisclosureButton
cell.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.5)
cell.imageView!.image = UIImage(named: checklist.iconName)
return cell
}
func cellForTableView(tableView: UITableView) -> UITableViewCell {
let cellIdentifier = "Cell"
if let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) {
return cell
} else {
return UITableViewCell(style: .Subtitle, reuseIdentifier: cellIdentifier)
}
}
这种情况下如何设置尺寸?
最佳答案
您使用 Storyboard吗?如果是这样,您可以使用自动布局并强制 imageView 的宽度和高度。您还可以通过自动布局将其附加到左侧。
还有一个不错的 cocoa pod,允许您以编程方式强制执行自动布局约束,称为 SnapKit .
关于swift - 如何更改单元格中的 ImageView 大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36865952/