问题描述:

I am trying to resize height of my textview by content. I am using following code in viewDidLoad:

var textField : UITextView!

textField = UITextView(frame: CGRect(x: 0, y: self.view.bounds.height/2 - 50, width: self.view.bounds.width, height: 36))

self.view.addSubview(textField)

textField.editable=true

textField.font = UIFont (name: "Helvetica Neue", size: 15)

textField.scrollEnabled=false

var amountOfLinesToBeShown:CGFloat = 6

var maxHeight:CGFloat = textField.font.lineHeight * amountOfLinesToBeShown

textField.sizeThatFits(CGSizeMake(textField.frame.size.width, maxHeight))

But it is not working. It looks fixed height.

How can I fix it?

网友答案:

You can set UITextField frame with respect to its content

textField.sizeThatFits(CGSizeMake(textField.frame.size.width, FLT_MAX))

This may help you

相关阅读:
Top