我使用Swift 3.0与Xcode 8,我有一些图像调整大小的问题。这里是我设置我的UIImage框架的代码。UIImageView不调整大小
open func setData(_ data: Any?, image: String) {
self.textLabel?.font = UIFont.boldSystemFont(ofSize: 10)
self.textLabel?.textColor = UIColor(hex: "000000")
if let menuText = data as? String {
self.textLabel?.text = menuText
}
self.imageView?.contentMode = UIViewContentMode.scaleToFill
self.imageView?.frame = CGRect(x: 12, y: 8, width: 10, height: 10)
self.imageView?.image = UIImage(named: image)
self.imageView?.clipsToBounds = true
}
这里是我在我的tableView中调用我的函数的地方。我没有设置图像的任何问题,但只有调整大小。当我使用较小的图像时,图像更小,当我使用更大的图像时,图像变大,不会调整大小。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = BaseTableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: BaseTableViewCell.identifier)
cell.setData(menus[indexPath.row], image: images[indexPath.row])
return cell
}
如果是一个默认的表格单元格内的ImageView的那么它可能有一些默认约束调整图像大小。你有没有尝试过制作自己的细胞亚类? –
@mag_zbc现在即将尝试 – DionizB