问题描述:

I have a custom UITableViewCell.

class ProductRow: UITableViewCell {

@IBOutlet weak var iconStack: UIStackView!

@IBOutlet weak var prdImage: UIImageView!

@IBOutlet weak var prdPrice: UILabel!

@IBOutlet weak var prdTitle: UILabel!

override func awakeFromNib()

{

super.awakeFromNib()

}

override func setSelected(_ selected: Bool, animated: Bool) {

super.setSelected(selected, animated: animated)

// Configure the view for the selected state

}

}

I load the UIImageView via extension

extension UIImageView {

public func imageFromUrl(urlString: String)

{

let myUrl = URL(string: "https://" + MobMenu.domain + "/" + MobMenu.shop + "/prd/" + urlString);

let task = URLSession.shared.dataTask(with: myUrl!)

{

data, response, error in

guard let data = data, error == nil else

{

print("error=\(error)")

return

}

DispatchQueue.main.async

{

self.image = UIImage(data: data)

}

}

task.resume()

}

}

I update the fields in the row via the tableview function

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

{

let myCell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! ProductRow

let prdDTO = prdList[indexPath.row];

//getURLImage(img : prdDTO.getPrdImg(), myCell : myCell)

myCell.prdTitle.text = prdDTO.getPrdTitle()

myCell.prdTitle.font = UIFont(name: "HelveticaNeue-Thin", size: 12)

myCell.prdPrice.text = prdDTO.getPrice()

myCell.prdImage.imageFromUrl(urlString: prdDTO.getPrdImg())

myCell.prdImage.contentMode = UIViewContentMode.scaleAspectFit

myCell.prdImage.clipsToBounds = true

}

The problem is this line of code myCell.prdImage.contentMode = UIViewContentMode.scaleAspectFit. Everything is as it should be if I remove it but if I remove it, the resulting image will be too big. If I leave it in there however the images gets pushed down the tableview

Image of app here

I spent many hours googling it but could not figure the problem. Please help. Many thanks

相关阅读:
Top