Created
December 22, 2016 20:32
-
-
Save JohannMG/1d5f321f2e2eca9046d450c27f6e90ff to your computer and use it in GitHub Desktop.
Get height for constrained width string.
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: CGFloat.greatestFiniteMagnitude) | |
| let boundingBox = (self as NSString).boundingRect(with: constraintRect, | |
| options: .usesLineFragmentOrigin, | |
| attributes: [NSFontAttributeName: font], | |
| context: nil) | |
| return boundingBox.height | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment