簡體   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