将可扩展的uitextview单元格添加到uicollectionview
当其中一个单元格是包含uitextview
的单元格时,我有收集视图。我想要的是将textView
添加到此单元格中,该单元将相应地扩展到输入文本。
我创建了具有文本视图内部文本视图的Uiview:
private var textView: UITextView = {
let textView = UITextView()
textView.translatesAutoresizingMaskIntoConstraints = false
textView.isUserInteractionEnabled = true
textView.isEditable = true
return textView
}()
内部我设置了对监督的约束如下:
private func setConstraints() {
let width: CGFloat = 312
textView.topAnchor.constraint(equalTo: topAnchor).isActive = true
textView.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
textView.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
textView.widthAnchor.constraint(equalToConstant: width).isActive = true
}
然后在单元格I内部设置这样的约束:
func setConstraints() {
textView.topAnchor.equalTo(topAnchor).isActive = true
textView.leftAnchor.equalTo(leftAnchor).isActive = true
textView.rightAnchor.equalTo(rightAnchor).isActive = true
textView.bottomAnchor.equalTo(bottomAnchor).isActive = true
}
我确实在文本视图增长后扩展时确实实现了行为,但是,我没有设置底部约束对于uitextview- uiview,当我在单元格中键入大量文本时,我的收集视图不会增长(滚动)的原因。 如何在内部使用UITEXTVIEW添加单元格,它将扩展其属于的收集视图?
I have collection view when one of it's cell is cell that contain UITextView
. What i want is to add textView
to this cell that will expand accordingly to entered text.
I created UIView that have text view inside:
private var textView: UITextView = {
let textView = UITextView()
textView.translatesAutoresizingMaskIntoConstraints = false
textView.isUserInteractionEnabled = true
textView.isEditable = true
return textView
}()
Inside i set up it's constraints to superview as following:
private func setConstraints() {
let width: CGFloat = 312
textView.topAnchor.constraint(equalTo: topAnchor).isActive = true
textView.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
textView.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
textView.widthAnchor.constraint(equalToConstant: width).isActive = true
}
Then inside cell i set constraints like that:
func setConstraints() {
textView.topAnchor.equalTo(topAnchor).isActive = true
textView.leftAnchor.equalTo(leftAnchor).isActive = true
textView.rightAnchor.equalTo(rightAnchor).isActive = true
textView.bottomAnchor.equalTo(bottomAnchor).isActive = true
}
I did achieve behaviour when cell is expanding after textView growth, but, i didn't set bottom constraint for UITextView->UIView, that why my collection view doesn't grow (scroll) when i type large bunch of text in my cell.
How to add cell with UITextView inside that will expand CollectionView it belongs to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为,使用手动估算文本视图高度和在这种方法中返回的一种更好的方法
比使用AutoLayout更加困难,但是提供了更多的控制和自定义可能性。
I think a better way to use manual estimation text view height and return one in
This approach is more difficult than using AutoLayout but gives more control and customization possibilities.