Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove underline on UITextView link

Tags:

ios

uitextview

I'm trying the following to format links on UITextView:

self.textView.linkTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor], NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleNone]};

The issue is that, the link color was changed to white, but it's still underlined.

How can I solve it?

This is my attributedString:

{
    NSColor = "UIDeviceRGBColorSpace 0.294118 0.254902 0.211765 1";
    NSFont = "<UICTFont: 0x7fd75a196010> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 24.00pt";
    NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 24, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 36, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
}url.com{
    CTForegroundColorFromContext = 1;
    DTGUID = "44B87A68-642A-41AA-8CBA-48531DB58C57";
    DTLinkHighlightColor = "UIDeviceRGBColorSpace 1 0 0 1";
    NSColor = "UIDeviceRGBColorSpace 0 0 0.933333 1";
    NSFont = "<UICTFont: 0x7fd75a196010> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 24.00pt";
    NSLink = "http://www.url.com";
    NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 24, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 36, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
    NSUnderline = 1;
}
{
    NSFont = "<UICTFont: 0x7fd75a196010> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 24.00pt";
    NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 24, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 36, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
}
like image 959
jherran Avatar asked Mar 18 '15 08:03

jherran


1 Answers

For Swift, it's simply:

textView.linkTextAttributes = [.underlineStyle: 0]
like image 131
Tamás Sengel Avatar answered Oct 21 '22 20:10

Tamás Sengel