UITextView : 链接属性的前景颜色不改变 (NSAttributedStringKey)

die*_*ego 2 xcode textview nsattributedstring swift swift4

我有 NSAttributedStringKey 和 UITextView 的问题

事实上,我正在尝试这样做:

在此处输入图片说明

这是理论上应该工作的代码

class ViewController: UIViewController,UITextViewDelegate {
 @IBOutlet weak var txtView: UITextView!
 override func viewDidLoad() {
    super.viewDidLoad()
    txtView.delegate = self;
    let linkAttributes : [NSAttributedStringKey : Any] = [
            .link: URL(string: "https://exemple.com")!,
            .font:UIFont.boldSystemFont(ofSize: 18),
            .foregroundColor: UIColor.blue] ;
    let attributedString = NSMutableAttributedString(string: "Just 
     click here to do stuff...")
    attributedString.setAttributes(linkAttributes, range: 
    NSMakeRange(5, 10))
     txtView.attributedText = attributedString;
}}
Run Code Online (Sandbox Code Playgroud)

但此代码显示此

在此处输入图片说明

所以我试图通过添加两行代码来解决这个问题:

 let linkAttributes : [NSAttributedStringKey : Any] = [
            .link: URL(string: "https://exemple.com")!,
            .font:UIFont.boldSystemFont(ofSize: 18),
            .foregroundColor: UIColor.blue,
            .strokeColor : UIColor.black,//new line
            .strokeWidth : -1,//new line
           ] ;
Run Code Online (Sandbox Code Playgroud)

不幸的是,显示器不是我想要的。

在此处输入图片说明

有人帮助我解决这个问题,我在互联网上搜索但一无所获。

提前致谢

信息:我为本出版物拍摄的第一张图片:UITextView 中的链接在 Swift 4 中不起作用

iMi*_*ike 5

似乎“.link”使用了 UITextView 的 tintColor。尝试设置 tintColor ...