Search code examples
iosswiftautolayout

UILabel height with autolayout not working


I need a dynamic height label based on text length. I have set lines = 0, and Line break = word wrap.

uilabel setting

But its not working

set text

result

Is there any setting that I've missed? Seems like the default behavior is not wrapping, but i have changed it to "word wrap" but the label height is still not expanding.


Solution

  • I did everything you did:

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.label1.text = "adsfadsf adf adfasdf adfadf adsfadf adfafasdfa adfadf adfadff adsfadfasdf adsfadfasf"
    }
    

    enter image description here

    enter image description here

    And this is what I got:

    enter image description here

    That's what you should get too. If you aren't, something else is going on.