dimgl dimgl - 4 months ago 23
Swift Question

Set frame height to zero in a UITextView

I'm having trouble setting the height for a

UITextView
frame completely to zero even when it contains no text. Here's what it looks like (the red is the
UITextView
).



I've tried setting the frame's height to zero from my code as well.

var frame = bodyTextView.frame
frame.size.height = 0
bodyTextView.frame = frame


My labels can have a frame height of zero but this
UITextView
just won't get smaller than the line height.

Answer

Are you using auto-layout or size classes ? If not use…

bodyTextView.frame = CGRectMake(bodyTextView.frame.origin.x, bodyTextView.frame.origin.y, bodyTextView.frame.size.width, 0)  

If you using auto-layout, then you should set up a height constraint on bodyTextView and use…

heightConstraintBodyTextView.constraint = 0
Comments