2

I am resizing a UITextView based on its content. I would like to be able to then get the height of the textview and place it in a variable:

var heightFloat: CGFloat

override func viewDidLayoutSubviews() {

        super.viewDidLayoutSubviews()

        let contentSize = self.definitionTextView.sizeThatFits(self.definitionTextView.bounds.size)
        var frame = self.definitionTextView.frame
        frame.size.height = contentSize.height
        self.definitionTextView.frame = frame

        heightFloat = contentSize.height
        NSLog("heightFloat = %@", heightFloat)

    }

And then when the application is ran, the console simply returns:

heightFloat = (null)

How do I get height of the textview be stored within heightFloat?

Daniel Bramhall
  • 1,451
  • 4
  • 18
  • 24

1 Answers1

1

Use CGRectGetHeight property.

heightFloat = CGRectGetHeight(self.definitionTextView.frame)
Fawad Masud
  • 12,219
  • 3
  • 25
  • 34