Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension UILabel {
- func getEstimatedHeight(width: CGFloat) -> CGFloat {
- guard let text = self.text else { return CGFloat.min }
- var maxHeight = CGFloat.max
- if (self.numberOfLines > 0) {
- maxHeight = (ceil(self.font.lineHeight) * CGFloat(self.numberOfLines))
- }
- let maxSize = CGSizeMake(width, maxHeight)
- let options = NSStringDrawingOptions.UsesFontLeading.union(.UsesLineFragmentOrigin)
- let estimatedSize = NSString(string: text).boundingRectWithSize(maxSize, options: options, attributes: [NSFontAttributeName: self.font], context: nil)
- return estimatedSize.height
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement