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?
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
You have to add contraints of 0 left and right from text view to the stack view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With