Thursday, February 21, 2019

Textview Swift

Swift use label to show text, but it have textView too. TextView have Scrollview inside, so if we want to show long text, use textView will better than label. If use label, we have to set.
la.numberLine =0
la.sizeToFit()
Declare to above viewDidLoad
var gi:UITextView!
Set position below super.
gi = UITextView(frame: CGRect(x:100, y: 0, width: 100, height: 60))
Make border.
gi.layer.borderWidth = 1
Set text.
gi.text = String manylines
Add to view.
view.addSubview(gi)
We can see the scroll mark at right edge when move cursor to.
If user touch finger on textview, keyboard will show and user can edit text. To prevent keyboard show, add this line.
gi.editable=false
If use this line.
gi.userInteractionEnabled=false

Keyboard not show but user can’t scroll down if text too long.

No comments:

Post a Comment