title: How to calculate boundRect correctly for NSAttributedString When apply shadow
body: <p>I tried apply shadow effect to UILabel using NSAttributeString. I want to change the size of UILabel whenever change shadow offset. However, it doesn't calculate correct frame and ignore shadow offset. How can I achieve?</p>
  <pre><code>    let textView = UILabel(frame: CGRect(x: 20, y: 100, width: 300, height: 50))
      textView.layer.borderColor = UIColor.red.cgColor
      textView.layer.borderWidth = 1
  
      textView.numberOfLines = 0
      textView.text = &quot;hyHgjpQ\nhyHgjpQ\nhyHgjpQ&quot;
      textView.font = UIFont(name: &quot;DamascusSemiBold&quot;, size: 40)
      textView.textColor = .white
      textView.textAlignment = .center
      self.view.addSubview(textView)
      
      
      var textAttributes: [NSAttributedString.Key: AnyObject] = [:]
  
      // font name &amp; size
      let font = UIFont(name: &quot;HelveticaNeue&quot;, size: 50)
      textAttributes[NSAttributedString.Key.font] = font
  
      // shadow
      let shadow = NSShadow()
      shadow.shadowBlurRadius = 10
      shadow.shadowOffset = CGSize(width: 10, height: 30)
      shadow.shadowColor = UIColor.red
      textAttributes[NSAttributedString.Key.shadow] = shadow
      
      textView.attributedText = NSAttributedString(string: textView.text ?? &quot;&quot;, attributes: textAttributes)
  
      let bound = textView.text!.boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude),
                                         options: .usesLineFragmentOrigin,
                                         attributes: textAttributes,
                                         context: nil)
      textView.bounds = bound
  </code></pre>
  <p><a href="https://i.stack.imgur.com/dpO1I.png" rel="nofollow noreferrer">Result</a></p>