Created
May 4, 2017 15:02
-
-
Save catqbat/c6b81967b5d5e92502075adb27962862 to your computer and use it in GitHub Desktop.
This file contains 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 width(withConstrainedHeight height: CGFloat, font: UIFont) -> CGFloat | |
{ | |
let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height); | |
let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil) | |
return boundingBox.width; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment