【发布时间】:2018-12-16 06:46:49
【问题描述】:
如何更改UIImageView 的width/height。我有很多不同 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)
【问题讨论】:
-
如果我没记错的话,
sizeframe的属性是ready only(只有get,没有set)。因此,取而代之的是,检索frame,并在保留原点的情况下重新计算它,并使用cell?.imageView?.frame = CGRect(origin: cell?.imageView?.frame.origin, size: CGSize(width: 10, height: 10))或cell?.imageView?.frame = CGRect(x: cell?.imageView?.frame.origin.x, y: cell?.imageView?.frame.origin.y, width: 10, height: 10)更改大小 -
那没用 :(
-
您希望实际的
UIImageView调整大小,还是希望固定大小并在其中调整实际图像的大小? -
这看起来只是您上一个问题stackoverflow.com/questions/51226153/…的副本
标签: swift uitableview uiimageview image-size