I have mentioned my code below where I want to adjust my label height according to the text. In the picture below, black background is the label and this label is inserted into a UIScrollView. Label is aligned with the top left corner of the scroll view but when I run my app following is the display of view controller i.e. label has gone far below the top left corner of the scrollview. Please help me in this matter
func getLabelsHeightAccordingToTheTextContent() -> CGFloat
{
let label:UILabel = UILabel(frame: CGRectMake(0, 0, 250, CGFloat.max))
label.numberOfLines = 0
label.font = outletLabel.font
label.text = outletLabel.text
label.lineBreakMode = NSLineBreakMode.ByWordWrapping
var fontName: String = outletLabel.font.fontName
label.font = UIFont (name: fontName, size: outletLabel.font.pointSize)
label.sizeToFit()
return label.frame.height
}
when i get the height of label, I set the height of scrollview
let height = getLabelsHeightAccordingToTheTextContent()
let width = outletScrollView.frame.width
following are the properties of the label....................................