instacart / Nantes

Swift TTTAttributedLabel replacement
Apache License 2.0
1.11k stars 85 forks source link

Attributed string attributes not preserved #67

Open andreaslindahl opened 4 years ago

andreaslindahl commented 4 years ago

When setting the attributedText property to an NSAttributedString, NantesLabel sets the text property of the label to attributedText.string instead of actually setting the attributedText property, which means that any formatting, and other attributes, set on the NSAttributedString aren't used.

Is it possible to use an NSAttributedString without losing all of the formatting and attributes?

override open var attributedText: NSAttributedString? {
    get {
        return _attributedText
    } set {
        guard newValue != _attributedText else {
            return
        }

        _attributedText = newValue
        setNeedsFramesetter()
        _accessibilityElements = nil
        linkModels = []

        checkText()

        setNeedsDisplay()
        invalidateIntrinsicContentSize()

        super.text = attributedText?.string
    }
}
andreaslindahl commented 4 years ago

Investigating this further, it seems most of the attributes, such as bold etc are preserved, but that some already existing paragraph styling is removed, such as headIndent.

bvirlet commented 4 years ago

Have you tried using:


    public func setAttributedText(_ attributedString: NSAttributedString, afterInheritingLabelAttributesAndConfiguringWithBlock block: ((NSMutableAttributedString) -> NSMutableAttributedString)?) ```
andreaslindahl commented 4 years ago

Yes, I tried that as well, with the same result.

frndev commented 3 years ago

Same here, it seems centered paragraph is not preserved.

bghenriques commented 3 years ago

Hi Andreas, I am using NantesLabel library on an iOS app and I have the exact same issue; the following settings are ignored:

paragraphStyle.firstLineHeadIndent paragraphStyle.headIndent paragraphStyle.paragraphSpacingBefore

It would be very important to have this corrected in the Library by the Nantes team.

andreaslindahl commented 3 years ago

Is anyone maintaining this library anymore?

ngoleo commented 3 years ago

@andreaslindahl sorry for the delay. i'm exploring whether we could preserve those attributes. will keep you updated.

darko55s commented 3 years ago

@ngocholo check the PR above, this should fix the head ident for attributed strings