简体   繁体   English

将 UITextView 的高度放在 CGFloat 变量中

[英]Place the height of UITextView in CGFloat variable

I am resizing a UITextView based on its content.我正在根据其内容调整UITextView的大小。 I would like to be able to then get the height of the textview and place it in a variable:我希望能够获得 textview 的高度并将其放置在一个变量中:

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 ?如何将 textview 的高度存储在heightFloat

使用CGRectGetHeight属性。

heightFloat = CGRectGetHeight(self.definitionTextView.frame)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM