optonaut / ActiveLabel.swift

UILabel drop-in replacement supporting Hashtags (#), Mentions (@) and URLs (http://) written in Swift
MIT License
4.47k stars 686 forks source link

Hide ActiveLabel with NSLayoutConstraint #375

Closed LebonNic closed 4 years ago

LebonNic commented 4 years ago

Hi!

First of all thank for this great pod! However, in my app I have a scenario where an ActiveLabel should be hidden dynamically. To do so, I set the text of the label to nil and I set its height to 0 through an attached NSLayoutConstraint. However, the ActiveLabel is still visible in the UI (as you can see in the first screen shot).

Simulator Screen Shot - iPhone 8 - 2020-09-14 at 17 26 18

If I remove "ActiveLabel" from the custom class (in the interface builder) it works as expected:

Simulator Screen Shot - iPhone 8 - 2020-09-14 at 17 32 09

It is normal? Is there a specific way to achieve this?

Best regards, Nicolas

LebonNic commented 4 years ago

This pull request https://github.com/optonaut/ActiveLabel.swift/pull/367 will fix the issue. While waiting for the pod update to be released, you can add manually these lines in the property intrinsicContentSize of the ActiveLabel class:

guard let text = text, !text.isEmpty else {
            return .zero
        }

Clean your project, rebuild and it will work!