Atributika icon indicating copy to clipboard operation
Atributika copied to clipboard

Style NSLink in NSAttributedString

Open damirstuhec opened this issue 3 years ago • 0 comments

Having an NSAttributedString which contains NSLinks, how can one style those links with Atributika?

I have the following code:

label.attributedText = content
    .styleLinks(Style.foregroundColor(Color.appTint, .normal).foregroundColor(Color.appTint, .highlighted))
    .styleAll(Style.foregroundColor(.black).font(font).backgroundColor(backgroundColor))

where content is an NSAttributedString containing NSLinks which I would like to style as well.

Here's a console print of the link component of the attributed string:

hyperlink{
    NSColor = "kCGColorSpaceModelRGB 0 0 0.933333 1 ";
    NSFont = "<UICTFont: 0x1530326c0> font-family: \".SFUI-Regular\"; font-weight: normal; font-style: normal; font-size: 14.67pt";
    NSKern = 0;
    NSLink = "https://google.com/";
    NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 22/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n), DefaultTabInterval 36, Blocks (\n), Lists (\n), BaseWritingDirection 0, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0";
    NSStrokeColor = "kCGColorSpaceModelRGB 0 0 0.933333 1 ";
    NSStrokeWidth = 0;
    NSUnderline = 1;
}

Is this currently possible? Thanks.

damirstuhec avatar Jan 27 '21 20:01 damirstuhec