Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode - Swift, UITextView won't display on UIStackView

I know that there's a question similar to this already, but his solution didn't solve my problem.

What I have is, I've used the storyboard to create a view controller, and then place a child stack view ontop.

Using IBOutlet, I've linked the UIStackView to the custom view controller class.

Everything's linked together correctly, this isn't the issue (I've made sure).

My problem is I can't seem to get a UITextView to display in the UIStackView.

here's my code (inside a function in the view controller):

let textView = UITextView()
textView.text = "test"
stackView.addArrangedSubview(textView) //stackView is the IBOutlet

I've been able to make the UITextView appear on the parent view using

let pos = CGRect(x: 100, y: 100, width: 200, height: 200)
let textView = UITextField(frame: pos)
textView.text = "test"
//stackView.addArrangedSubview(textView)
self.view.addSubview(textView)

And no, it doesn't work to uncomment the line with stackView, then comment out the self.view.addSubview

But I manage to get something to appear in the UITabView if I use a UITextField. This is beyond annoying....

Any suggestions?

like image 327
HumbleWebDev Avatar asked Apr 27 '16 18:04

HumbleWebDev


2 Answers

The stack view does not know the size of the text view because it is scrollable by default. You need to disable scrolling:

textView.isScrollEnabled = false
like image 174
Sune Avatar answered Nov 16 '22 02:11

Sune


You have to add contraints of 0 left and right from text view to the stack view.

like image 26
MedMind Avatar answered Nov 16 '22 01:11

MedMind