繁体   English   中英

以编程方式创建时 UITextView 不滚动

[英]UITextView not scrolling when created programmatically

我正在以编程方式创建 UITextView。

content = UITextView(frame: CGRect(x: 0, y: header.frame.origin.y + header.frame.size.height, width: self.frame.size.width, height: self.frame.size.height - viewTop.frame.size.height))
content.font = UIFont.init(name: "OpenSans", size: 17)
content.textColor = UIColor.black
content.backgroundColor = UIColor.white
content.isUserInteractionEnabled = true
content.isScrollEnabled = true
content.isEditable = true
content.isSelectable = true
content.bounces = true
content.showsVerticalScrollIndicator = true  
self.addSubview(content)  

虽然它没有滚动。

只有当内容大小大于 textView 的框架时,TextView 才会滚动。 因此,在使用足够的文本设置 textView 的文本时,应该允许它滚动。

似乎添加 textview 的代码可能在viewDidLoad方法中。 当您在viewDidLoad方法中添加任何视图时,该视图很可能没有适当的框架和内容大小。 任何其他观点也很有可能与之重叠。 您可以通过单击调试视图来检查 调试区中的图像。

如果上述情况是正确的,那么您可以通过将content.bringSubview(toFront: self.view)放入viewDidApear方法来解决问题。

您已将内容视图添加到它自己。 将此更改为查看,它将滚动。

view.addSubview(content)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM