Kyr*_*dis 0 uitableview uiimageview image-size swift
我如何更改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!
}
Run Code Online (Sandbox Code Playgroud)
我想让这行代码工作:
cell?.imageView?.frame.size = CGSize(width: 10, height: 10)
Run Code Online (Sandbox Code Playgroud)
代替:
cell?.imageView?.frame.size = CGSize(width: 10, height: 10)
Run Code Online (Sandbox Code Playgroud)
和:
cell?.imageView?.translatesAutoresizingMaskIntoConstraints = false
cell?.imageView?.heightAnchor.constraint(equalToConstant: 10).isActive = true
cell?.imageView?.widthAnchor.constraint(equalToConstant: 10).isActive = true
Run Code Online (Sandbox Code Playgroud)
看起来您希望cell是可选的,但如果上述方法不起作用,请尝试删除问号。
| 归档时间: |
|
| 查看次数: |
6778 次 |
| 最近记录: |