2017-03-28 17 views
-1

プログラムでUITextViewを作成しています。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) 

ただし、スクロールしません。

+0

書き込み=> content.text = "Hello World!" – iPatel

+0

本文にテキストがありますか?表示 –

+0

@HabibAli:テキストはありません。これは入力用です。 – Nitish

答えて

0

TextViewは、Content SizeがtextViewのフレームよりも大きい場合にのみスクロールします。 TextViewのテキストを十分なテキストで設定すると、スクロールできるようになります。

0

textviewを追加するコードがおそらくviewDidLoadメソッドにあるようです。 viewDidLoadメソッドでビューを追加すると、ビューに適切なフレームとコンテンツサイズがない可能性があります。また、他のビューがそれを忘れる可能性もあります。デバッグ領域のイメージをクリックすると、ビューをデバッグして確認できます。

上記のシナリオが正しい場合は、content.bringSubview(toFront: self.view)viewDidApearメソッドに入れて問題を解決できます。