iOS - UITextView size.height比文本更大

时间:2014-09-07 19:47:56

标签: ios swift uitextview

我创建了代码:

var sampleText = "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda."

    var emptyView = UIView()
    self.view.addSubview(emptyView)
    var frame = CGRect()
    frame = emptyView.frame
    frame.origin.x = 0
    frame.origin.y = 10
    frame.size.width = self.view.frame.width
    emptyView.frame = frame
    var textView = UITextView()
    textView.text = sampleText
    var frameTextView = CGRect()
    frameTextView = emptyView.frame
    textView.frame = frameTextView
    textView.font = UIFont(name: "Helvetica Neue", size: 12)
    textView.textColor = UIColor.blackColor()
    emptyView.addSubview(textView)
    textView.sizeToFit()
    textView.layoutIfNeeded()

当打印("(textView.frame.size.height)")我得到了159,5,这个视图在屏幕上显得更大。为什么我的textView.frame是如此高度?

0 个答案:

没有答案