Last active
May 16, 2019 22:09
-
-
Save reeichert/965799c7677a9df2e6270a326d3ae5a3 to your computer and use it in GitHub Desktop.
heightWithConstrainedWidth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
func heightWithConstrainedWidth(width: CGFloat, font: UIFont) -> CGFloat { | |
let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude) | |
let boundingBox = self.boundingRect(with: constraintRect, | |
options: .usesLineFragmentOrigin, | |
attributes: [NSAttributedString.Key.font: font], | |
context: nil) | |
return boundingBox.height | |
} | |
} |
Author
reeichert
commented
May 16, 2019
- Updated to Swift 5
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment