title: UICollectionView cell fixed width and dynamic height using constraints in swift
body: <p>I have one collectionview and a cell inside that which is having a fixed width and dynamic height based on its contents.I am using autolayout constraints , my code is below.</p>
  
  <p>I have already tried to set all types of auto constraints inside the cell and inside the view .</p>
  
  <pre><code>    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
              return 5
          }
  
          func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
              let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! ViewControllerCell
  
              cell.lbl_text.text = "djs sdfs sdfs dsfsfd gdgfd dfgd df "
  
              return cell
  
          }
  
  
  
          override func viewDidLoad() {
              super.viewDidLoad()
              // Do any additional setup after loading the view.
  
              if let flowLayout = coll_main?.collectionViewLayout as? UICollectionViewFlowLayout {
                  flowLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
  
              }
  
  
  
      }
  
  In cell class method:
  override func awakeFromNib() {
          super.awakeFromNib()
          self.contentView.autoresizingMask = [UIView.AutoresizingMask.flexibleHeight]
      }
  
      override func layoutSubviews() {
          self.layoutIfNeeded()
      }
  </code></pre>
  
  <p>i get cell width fix without i am set that width. how may this issue solve?</p>
  
  <p>here screenshots.</p>
  
  <p><a href="https://i.stack.imgur.com/C7wXl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/C7wXl.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/BRJT6.png" rel="noreferrer"><img src="https://i.stack.imgur.com/BRJT6.png" alt="enter image description here"></a></p>