title: How to calculate height of a String?
body: <p>I am trying to adjust the cell height resize to fit the UILabel text, but it is not working..</p>
  
  <pre><code>var mySize = CGFloat()
      func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
          let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! cellView
  
          cell.myLabel.text = self.items[indexPath.item]
          cell.myLabel.bounds.size.height = self.mySize
  
          cell.backgroundColor = UIColor.yellowColor()
  
          return cell
      }
  
      func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
          // handle tap events
          print("You selected cell #\(indexPath.item)!")
      }
  
      func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -&gt; CGSize {
  
          func heightForLabel(text:String, font:UIFont, width:CGFloat) -&gt; CGFloat
          {
              let label:UILabel = UILabel(frame: CGRectMake(0, 0, width, CGFloat.max))
              label.numberOfLines = 0
              label.lineBreakMode = NSLineBreakMode.ByWordWrapping
              label.font = font
              label.text = items[indexPath.row]
  
              label.sizeToFit()
              return label.frame.height
          }
  
          let font = UIFont(name: "Helvetica Neue", size: 30)
          let detailHeight = heightForLabel(items[indexPath.row], font: font!, width: UIScreen.mainScreen().bounds.size.width)
  
          self.mySize = detailHeight
  
          return CGSizeMake(UIScreen.mainScreen().bounds.size.width, 358 + detailHeight)
      }
  </code></pre>
  
  <p>Any suggestions what to do here? Should i do it another way? Please, I need help.. The problem is that the UILabel text is set in the <code>cellForItemAtIndexPath</code>, and <code>items</code> is an array for strings.</p>
  
  <p>This is my project file, if someone watch to take a look at it:
  <a href="http://www.filedropper.com/test_37" rel="noreferrer">http://www.filedropper.com/test_37</a></p>