Last active
May 4, 2017 12:19
-
-
Save JayachandraA/8ee5a9d1f1d98c0abdf2a8907cc13836 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 UILabel{ | |
func dynamicHeight() -> CGFloat { | |
let label = UILabel(frame: self.bounds) | |
label.numberOfLines = self.numberOfLines | |
label.lineBreakMode = self.lineBreakMode | |
label.font = self.font | |
label.text = self.text | |
label.sizeToFit() | |
return label.frame.size.height | |
} | |
} |
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
let myLable = UILabel(frame: CGRect(x: 10, y: 20, width: 100, height: 20)) | |
myLable.text = "Implements a read-only text view. A label can contain an arbitrary amount of text, but UILabel may shrink, wrap, or truncate the text, depending on the size of the bounding rectangle and properties you set. You can control the font, text color, alignment, highlighting, and shadowing of the text in the label." | |
myLable.numberOfLines = 0 | |
let expectedHeight = myLable.dynamicHeight() | |
myLable.frame = CGRect(x: 10, y: 20, width: 100, height: expectedHeight) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment