I am using this link to resize a textView dynamically. However, I implement it into a function and it return a height of 238. Using the heirarchy viewer I can see my textView is indeed 238, but there is a ton of empty space as 238 is way taller than needed. Can anyone figure out why textView.sizeThatFits:
would give me this kind of error? Here is my code.
func heightOfTextFieldForMessage(message : String) -> CGFloat {
let horizontalMargin = CGFloat(194)
let textView = UITextView()
textView.text = message
textView.font = UIFont.systemFontOfSize(14)
//This width is same as in heirachy viewer, horizontalMargin is a constant distance the textView is from edges of the screen.
let fixedWidth = self.view.frame.width - horizontalMargin
let newSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max))
let height = newSize.height
print(height)
return height
}
Is it possibly because my font is smaller than the default font? I tried changing the textView
's font size before resizing but it seems like like the height does change based on what I set the font to.
The Text View bottom constraint is tied to the top of the icon so as you can see the textView is way taller than needed.