title: How to set fix ImageView size inside TableViewCell programmatically?
body: <p>I have this issue wherein I need to fix the size on an image inside a tableviewcell. The image below shows that the <strong>image size</strong> in not uniform. </p>
  
  <p><a href="https://i.stack.imgur.com/PTujo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PTujo.png" alt="image"></a> </p>
  
  <p>Here are the codes I used.</p>
  
  <pre><code> if noteImageIsAvailable == true {
          if let imageData = assignedNotePhoto?.photoData {
              if let image = Utilities.resizePictureImage(UIImage(data: imageData as Data)) {
                  //added fix
                  cell.imageView?.frame.size = CGSize(width: 36, height: 24)
                  cell.imageView?.clipsToBounds = true
                  //-----
                  cell.imageView?.contentMode = .scaleAspectFill
                  cell.imageView?.image = image
              }
          }
      }
  </code></pre>
  
  <p>I read an answer here in stackoverflow. It says I need to add <code>clipToBounds</code> but unfortunately it doesn't work. Please help me solve this issue. Thank you</p>
  
  <p><strong>TableView Code</strong></p>
  
  <pre><code>extension SettingNoteViewController: UITableViewDataSource, UITableViewDelegate {
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return Menu.SettingNote.items.count
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "reuseIdentifier")
      let keyPass = KeyHelper.NoteSetting.info[indexPath.row]
      let assignedNotePhoto = self.getNotePhoto(key: keyPass.key)
      let assignedNoteTextData = self.getNoteTextData(key: keyPass.key)?.value
  
      cell.contentView.backgroundColor = .black
      cell.textLabel?.textColor = .white
      cell.detailTextLabel?.textColor = .white
      cell.detailTextLabel?.numberOfLines = 0
      let noteImageIsAvailable = assignedNotePhoto?.photoData != nil
  
      if noteImageIsAvailable == true {
          if let imageData = assignedNotePhoto?.photoData {
              if let image = Utilities.resizePictureImage(UIImage(data: imageData as Data)) {
                  //added fix
                  cell.imageView?.translatesAutoresizingMaskIntoConstraints = false
                  cell.imageView?.frame.size = CGSize(width: 36, height: 24)
                  cell.imageView?.clipsToBounds = true
                  //-----
                  cell.imageView?.contentMode = UIView.ContentMode.scaleAspectFit
                  cell.imageView?.image = image
              }
          }
      }
      cell.textLabel?.text = Menu.SettingNote.items[indexPath.row].value
      cell.detailTextLabel?.text = assignedNoteTextData ?? "noteSettingSubTitle".localized
  
      return cell
  }
  
  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      if segue.destination is InputMemoViewController {
          let vc = segue.destination as! InputMemoViewController
          vc.infoNoteKey = self.infoNoteKeyToPass
          vc.infoLabelText = self.infoLabelToPass
      }
  }
  
  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      self.infoNoteKeyToPass = KeyHelper.NoteSetting.info[indexPath.row].key
      self.infoLabelToPass = KeyHelper.NoteSetting.info[indexPath.row].label
      self.performSegue(withIdentifier: "showInputMemo", sender: self)
  }
  
  func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
     return 80
     }
  }
  </code></pre>
  
  <p>The image below was the output when I applied @Kishan Bhatiya solution. 
  <a href="https://i.stack.imgur.com/UAJnb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UAJnb.png" alt="output"></a></p>
  
  <p>The first and second image is a landscape photo and the third image is in portrait
  <a href="https://i.stack.imgur.com/jjsrn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jjsrn.png" alt="output2"></a></p>