Created
April 16, 2016 09:18
-
-
Save khanhldt/815194d4451fcdff904c909f5e259617 to your computer and use it in GitHub Desktop.
Utility function to get the needed height for a string to be displayed in a UIKit component
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
public static func heightNeeded(text:String, font:UIFont, width:CGFloat) -> CGFloat{ | |
let label:UILabel = UILabel(frame: CGRectMake(0, 0, width, CGFloat.max)) | |
label.numberOfLines = 0 | |
label.lineBreakMode = NSLineBreakMode.ByWordWrapping | |
label.font = font | |
label.text = text | |
label.sizeToFit() | |
return label.frame.height | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment