我正在尝试创建一个文本视图,其高度跟随其中的行数。我一直在研究约束,但在这里我有一个奇怪的问题:
这是代码
func textViewDidChange(textView: UITextView) { //Handle the text changes here
if(textView.text != ""){
self.animateSendButton(true)
}else{
self.animateSendButton(false)
}//the textView parameter is the textView where text was changed
heightTextfieldConstraint.constant = self.textField.contentSize.height + 2
textField.contentInset.top = 1
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么会有这 3 种不同的情况,你有什么解决办法吗?
您可以尝试在顶部、机器人、左侧和右侧添加一个插图,即使出现第二行,也应该使文本居中。
textView.textContainerInset = UIEdgeInsetsMake(5, 5, 5, 5)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3520 次 |
| 最近记录: |