evermeer / AttributedTextView

Easiest way to create an attributed UITextView (with support for multiple links and from html)
Other
440 stars 55 forks source link

paragraphAlignRight or paragraphAlignCenter is not working #2

Closed ramunasjurgilas closed 7 years ago

ramunasjurgilas commented 7 years ago

paragraphAlignRight is not working. Below I posted how I am using it.

        textView.attributer = "by_clicking_tou_pp".white
            .match(.terms_of_use).underline.makeInteract({ (link) in
            print("TODO: open terms of user screen")
        })
            .match(.privacy_policy).underline.makeInteract({ (link) in
            print("TODO: open privacy policy")
        }).paragraphAlignRight
evermeer commented 7 years ago

Hi,

paragraph styling is a combination of multiple style features in one. Because of that it needs to be applied separately. At the end of your code you need to call .paragraphApplyStyling

ramunasjurgilas commented 7 years ago

Thanks for the quick answer, but unfortunately it did not work. Now I have like that:

        textView.attributer = "by_clicking_tou_pp".white
            .match(.terms_of_use).underline.makeInteract({ (link) in
            print("TODO: open terms of user screen")
        })
            .match(.privacy_policy).underline.makeInteract({ (link) in
            print("TODO: open privacy policy")
        }).paragraphAlignRight.paragraphApplyStyling
evermeer commented 7 years ago

ah... you did a .match. When doing that, the active selection will be set to that match. So you are applying the paragraph styling to only the seleted .privacy_policy. You want the styling on the entire text. I did a test in the demo app and added the following:

    func showSample8() {
        attributedTextView.attributer = decorate(6) { content in return (content + (
            "The quick brown fox jumps over the lazy dog.\nPack my box with five dozen liquor jugs.\nSeveral fabulous dixieland jazz groups played with quick tempo.".brown
                .match("brown fox").underline.makeInteract { (link) in
                    print("TODO: open terms of user screen")
                }
                .match("fabulous dixieland").underline.makeInteract { (link) in
                    print("TODO: open privacy policy")
                }.all.paragraphAlignRight.paragraphApplyStyling
            ))
        }
    }

The result of that is:

screen shot 2017-02-20 at 10 54 58
ramunasjurgilas commented 7 years ago

Thanks for the quick support! Now works as designed! 👍