evermeer / AttributedTextView

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

can't set dotted underline. #14

Closed vatsal1992 closed 6 years ago

vatsal1992 commented 6 years ago

Hello there, This is i tried,

attributedTextView.attributer = decorate(7) { 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(.patternDot).makeInteract { (link) in
                    print("TODO: open privacy policy")
                }.all.paragraphAlignRight.paragraphApplyStyling
            ))
        }
evermeer commented 6 years ago

You can use any underline style from https://developer.apple.com/documentation/appkit/nsunderlinestyle

so you could say .underline(.patternDot)

vatsal1992 commented 6 years ago

actually, i've downloaded latest example and gave a try .underline(.patternDot) but this doesn't seems working . that's why i raised an issue.

but anyway thanks for immediate response. 👍

evermeer commented 6 years ago

You where right. If you want a pattern, then the values need to do an or with the style.

I tried this by adding this code to the attributer:

    open func underline(raw: Int) -> Attributer {
        return applyAttributes(NSAttributedStringKey.underlineStyle.rawValue, value: NSNumber(value: raw))
    }

And then calling it like this:

.append("Tap on ").black.underline(raw: (NSUnderlineStyle.patternDash.rawValue | NSUnderlineStyle.styleSingle.rawValue))`

But I do want a cleaner call to the underline function. I think I will add an underline function with 2 parameters (one for the style and one for the pattern)

evermeer commented 6 years ago

Ok, that works. When I add this:

    open func underline(_ style: NSUnderlineStyle, _ pattern: NSUnderlineStyle) -> Attributer {
        return applyAttributes(NSAttributedStringKey.underlineStyle.rawValue, value: NSNumber(value: (style.rawValue | pattern.rawValue)))
    }

it can be called with: .append("Tap on ").black.underline(.styleDouble, .patternDashDotDot)

I will push that code later today to GitHub

evermeer commented 6 years ago

its pushed as version 0.7.0

evermeer commented 6 years ago

If you have any other issues, then just let me know.