【问题标题】:change uitextview hyperlink color [duplicate]更改uitextview超链接颜色[重复]
【发布时间】:2017-11-22 22:53:20
【问题描述】:

我正在使用UITextView,并且我想更改我在此组件中使用的超链接的颜色。例如,如果 UITextView 显示 www.gmail.com,则它显示为蓝色。我想改变那个颜色。

【问题讨论】:

    标签: ios uitextview


    【解决方案1】:

    嘘! Apple 已经发布了适用于 iOS7 的解决方案!如this answer 中所述,您可以使用UITextViewlinkTextAttributes 属性。带下划线的白色链接如下所示:

    yourTextView.linkTextAttributes = @{
        NSForegroundColorAttributeName: [UIColor whiteColor], 
        NSUnderlineStyleAttributeName: [NSNumber numberWithInt:NSUnderlineStyleSingle]
    };
    

    或者您也可以更改tintColor,因为UITextView 继承自UIView 并使用tintColor 属性为链接着色 - 请参阅:

    yourTextView.tintColor = [UIColor whiteColor];
    

    现在您的链接看起来很棒!

    【讨论】:

    • 通过设置 yourTextView.linkTextAttributes 更改链接颜色使光标看起来像是悬停在文本上而不是链接上(手形光标)。有没有办法解决这个问题?
    • 我找到了解决光标问题的方法:yourTextView.linkTextAttributes = [NSForegroundColorAttributeName : UIColor.redColor(), NSUnderlineStyleAttributeName : NSUnderlineStyle.StyleSingle.rawValue, NSCursorAttributeName: NSCursor.pointingHand()]
    • 第二个适合我
    【解决方案2】:

    简单的答案是你做不到。

    这里有一个解决方法:

    Can I change the color of auto detected links on UITextView?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-04
      • 1970-01-01
      • 2016-01-01
      • 2011-11-07
      • 1970-01-01
      • 2018-09-27
      • 2018-07-21
      • 2021-05-14
      相关资源
      最近更新 更多