title: Fixed Size for UIImageView Inside UITableViewCell in iOS 11
body: <p>I am using the default UITableViewCell which comes with UIImageView, titleLabel and also a description Label. I want to have a fixed size for my UIImageView so all the images are of the same size. At present it looks like this: </p>
  
  <p><a href="https://i.stack.imgur.com/fcnKc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fcnKc.png" alt="enter image description here"></a></p>
  
  <p>The row height for the cell is "Automatic" and here are the properties of the UITableView. </p>
  
  <p><a href="https://i.stack.imgur.com/yXGZE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yXGZE.png" alt="enter image description here"></a></p>
  
  <p>How can I make my UIImageView fixed size?</p>
  
  <p>The images are downloaded asynchronously as shown below: </p>
  
  <pre><code>  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
          let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
          let dish = self.dishes[indexPath.row]
          cell.textLabel?.text = dish.title
          cell.imageView?.image = UIImage(named: "placeholder")
  
          cell.detailTextLabel?.text = dish.description
  
          cell.imageView?.setImageFor(url: URL(string: dish.imageURL)!) { image in
              cell.imageView?.image = image
              cell.imageView?.translatesAutoresizingMaskIntoConstraints = false
              cell.imageView?.widthAnchor.constraint(equalToConstant: 50)
              cell.imageView?.heightAnchor.constraint(equalToConstant: 50)
              cell.setNeedsLayout()
          }
  
          return cell
  
      }
  </code></pre>
  
  <p><strong>UIImageView+Additions.swift</strong></p>
  
  <pre><code>func setImageFor(url :URL, completion: @escaping (UIImage) -&gt; ()) {
  
          DispatchQueue.global().async {
  
              let data = try? Data(contentsOf: url)
  
              if let data = data {
  
                  let image = UIImage(data: data)
  
                  DispatchQueue.main.async {
  
                      completion(image!)
  
                  }
              }
          }
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/BBbvM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BBbvM.png" alt="enter image description here"></a></p>