在UITableViewCell中更改imageView的位置

时间:2015-08-15 13:35:30

标签: swift uitableview ios8 uiimageview

我想在UITableViewCell(cell.imageView ...)中更改默认imageView的位置。是可以这样做还是我必须创建一个新的?

1 个答案:

答案 0 :(得分:1)

迅速4:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = UITableViewCell()

    let iconImageView = UIImageView()
    iconImageView.image = UIImage(named: "yourImageName")
    cell.addSubview(iconImageView)

    iconImageView.translatesAutoresizingMaskIntoConstraints = false

    iconImageView.topAnchor.constraint(equalTo: cell.topAnchor, constant: 20).isActive = true
    iconImageView.rightAnchor.constraint(equalTo: cell.rightAnchor, constant: -40).isActive = true
    iconImageView.bottomAnchor.constraint(equalTo: cell.bottomAnchor).isActive = true
    iconImageView.widthAnchor.constraint(equalTo: cell.heightAnchor, constant: -20).isActive = true

    return cell
}