title: Unable to resize imageview after applying ratio to the image sdWebImage Swift
body: <p>I am having trouble with loading from url resized to custom ratio image through sdwebimage and resizing my imageview. I have tried many options with the imageview content mode, but none has work. My table view is resizable and has estimated row 300 and I have applied automaticDimension (and even has applied (tableView.autoresizingMask = UIView.AutoresizingMask.flexibleHeight). If you could give great example in code, that would be very helpful.</p>
  
  <p>Thank you very much in advance. </p>
  
  <p>My tableview code is:</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
      view.backgroundColor? = UIColor.blue
      tableView.frame = UIScreen.main.bounds
      tableView.register(OffersTVCell.self, forCellReuseIdentifier: reuseIdentifer)
      tableView.delegate = self
      tableView.dataSource = self
      view.addSubview(tableView)
      tableView.backgroundColor? = UIColor.blue
      tableView.separatorStyle = .none
  
      tableView.estimatedRowHeight = 300
      tableView.rowHeight = UITableView.automaticDimension
  
  }
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return welcomePages.count
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifer, for: indexPath) as! OffersTVCell
      cell.backgroundColor? = .red
  
      let pages = welcomePages[indexPath.row]
      let size = (Constants.screenWidth * 0.88)
      cell.offerImageView.sd_setImage(with: URL(string: pages.pageImage), placeholderImage: nil) { (image: UIImage?, error: Error?, cacheType:SDImageCacheType!, imageURL: URL?) in
          guard let cellImage = image else { return }
          let image = self.resizeImage(image: cellImage, newWidth: size)
          cell.offerImageView.image = image
  
      }
  
      return cell
  }
  
  func resizeImage(image: UIImage, newWidth: CGFloat) -&gt; UIImage {
  
      let scale = newWidth / image.size.width
      let newHeight = image.size.height * scale
      UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight))
      image.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: newHeight))
      let newImage = UIGraphicsGetImageFromCurrentImageContext()
      UIGraphicsEndImageContext()
  
      return newImage!
  }
  </code></pre>
  
  <p>and my tableview cell code is:</p>
  
  <pre><code>class OffersTVCell: UITableViewCell, SDWebImageManagerDelegate {
  
  let offerImageView: UIImageView = {
      let iv = UIImageView(frame: CGRect.init(x: 0, y: 0, width: 0, height: 0))
      iv.layer.cornerRadius = 13
      iv.clipsToBounds = true
      iv.translatesAutoresizingMaskIntoConstraints = false
  
      return iv
  }()
  
  
  
  override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
      super.init(style: style, reuseIdentifier: reuseIdentifier)
  
      let imageSize = (Constants.screenWidth * 0.88)
      contentView.addSubview(offerImageView)
  
      offerImageView.topAnchor.constraint(equalTo: topAnchor).isActive = true
  
      offerImageView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
  
      offerImageView.widthAnchor.constraint(equalToConstant: imageSize).isActive = true
      offerImageView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
      layoutIfNeeded()
      self.selectionStyle = .none
  }
  
  required init?(coder aDecoder: NSCoder) {
      fatalError("init(coder:) has not been implemented")
  }
  </code></pre>
  
  <p>the rows appear like that:</p>
  
  <p><a href="https://i.stack.imgur.com/SdPNa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SdPNa.png" alt="enter image description here"></a></p>