Mubaloo / wwdc2015-uistackviews

A quick run through the new UIStackViews API
Other
3 stars 0 forks source link

Question: UILabels with Dynamic Height #1

Open SpacyRicochet opened 9 years ago

SpacyRicochet commented 9 years ago

Have you had any luck with implementing a UIStackView with a label in it with a dynamic height? I'm trying to reimplement UIAlertController as a UIStackView exercise. This is tripping me up.

screen shot 2015-06-30 at 16 14 12

rhodgkins commented 9 years ago

Yeah - I've come across a similar issue. I'm not sure if the UILabel is ignoring its preferredMaxLayoutWidth or its something else. Hopefully it'll be fixed by final release.

I haven't tried this, but have you looked at sub-classing UILabel and then in layoutSubviews setting preferredMaxLayoutWidth to bounds.width - 1?

Cheers,

Rich

JonathanDowning commented 9 years ago

I've also experienced this issue (as of iOS 9/Xcode 7 beta 3) and doing what rhodgkins suggested worked!

class FixedLabel: UILabel {

    override func layoutSubviews() {
        super.layoutSubviews()
        preferredMaxLayoutWidth = bounds.width - 1
    }

}

I also hope that this is fixed before final release :)

aehlke commented 8 years ago

Anyone found alternative solutions? The last one pegs CPU (infinite loop of layoutSubviews re-triggering)

liamnichols commented 8 years ago

What exactly are you doing with them for it to kill the CPU? It all seems to kinda just work in iOS 9 from what I've seen

Sent from my iPhone

On 1 Nov 2015, at 03:58, Alex Ehlke notifications@github.com wrote:

Anyone found alternative solutions? The last one pegs CPU (infinite loop of layoutSubviews re-triggering)

— Reply to this email directly or view it on GitHub.