UITextView added from code missing in UIStackView

会有一股神秘感。 提交于 2019-12-05 10:44:18

UITextView is a subclass of UIScrollView and as such it's size is ambiguous inside UIStackVIew. To make the size unambiguous you make it resize itself based on it's content - i.e. make in not scrollable. The simple solution is then:

textView.isScrollEnabled = false

(Swift 3.0 syntax)

I figured out what's missing. I can't use the designated initializer, because I don't know the frame size of the text view in the class I'm creating it in.

But this helped - adding this line after stackView.distribution in the code above:

 self.alignment = UIStackViewAlignment.Fill

Try using

init(frame frame: CGRect,textContainer textContainer: NSTextContainer?)

As it's the designated initializer for a UITextView.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!