Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. func heightOfString(_ string: String, attributes: [NSAttributedString.Key: Any], fitting width: CGFloat) -> CGFloat {
  2.  
  3. let constraintRect = CGSize(width: width, height: CGFloat.greatestFiniteMagnitude)
  4. let boundingRect = string.boundingRect(with: constraintRect,
  5. options: [.usesLineFragmentOrigin, .usesFontLeading],
  6. attributes: attributes,
  7. context: nil)
  8.  
  9. return boundingRect.size.height
  10. }
  11.  
  12. func heightOfAttributedString(_ attributedString: NSAttributedString, fitting width: CGFloat) -> CGFloat {
  13.  
  14. let constraintRect = CGSize(width: width, height: CGFloat.greatestFiniteMagnitude)
  15. let boundingRect = attributedString.boundingRect(with: constraintRect,
  16. options: [.usesLineFragmentOrigin, .usesFontLeading],
  17. context: nil)
  18.  
  19. return boundingRect.size.height
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement