我创建了代码:
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是如此高度?