如何更改width/height
中的UIImageView
。我有很多图片带有不同的width/height
,我希望它们以imageView的大小显示。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
let city = nicosiaPlaces [indexPath.row]
cell?.textLabel?.text = city
cell?.imageView?.image = UIImage(named: city)
cell?.imageView?.frame.size = CGSize(width: 10, height: 10)
return cell!
}
我想使这一行代码起作用:
cell?.imageView?.frame.size = CGSize(width: 10, height: 10)
答案 0 :(得分:0)
替换:
cell?.imageView?.frame.size = CGSize(width: 10, height: 10)
使用:
cell?.imageView?.translatesAutoresizingMaskIntoConstraints = false
cell?.imageView?.heightAnchor.constraint(equalToConstant: 10).isActive = true
cell?.imageView?.widthAnchor.constraint(equalToConstant: 10).isActive = true
您似乎希望cell
是可选的,但是如果上述方法不起作用,请尝试删除问号。