the empty space on the end我正在考虑文本视图文本(我正在编写的文本视图)的大小,并将其设置为我正在显示的文本视图的大小。但是如果写较长的文本,当我发布它时,它会在文本视图中显示更长的空白区域。我通过测量我正在写的textV的content.height来为我的文本视图的大小制作代码。
} else if identifier == "save" {
print("Save button tapped")
if textViewWrite.text == "" {
print("text empty")
}
else{
print("\(textViewWrite.contentSize.height)")
let size: CGSize = textViewWrite.sizeThatFits(CGSize.init(width: textViewWrite.frame.size.width, height: CGFloat.greatestFiniteMagnitude))
let insets: UIEdgeInsets = textViewWrite.textContainerInset;
let relevantHeight = size.height - insets.top - insets.bottom;
let text = Post(texts: "String", textHeight: relevantHeight, textWidth: textViewWrite.contentSize.width)
PostService.create(text: self.textViewWrite.text!, height: Int(textViewWrite.contentSize.height), width: Int(view.frame.width) )
print("\(textViewWrite.contentSize.height)")
// 1
let HomeViewController = segue.destination as! HomeViewController
// 2
HomeViewController.posts.append(text)
}
textViewWrite.text = ""
}
}