gpt4 book ai didi

swift - 更改 UITableViewCell 中 imageView 的位置

转载 作者:可可西里 更新时间:2023-11-01 02:19:25 25 4
gpt4 key购买 nike

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

最佳答案

swift 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
}

关于swift - 更改 UITableViewCell 中 imageView 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32025258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com