为什么超链接有时不与NSAttributedString一个的NSTextField说明了什么?
-
22-09-2019 - |
题
在的NSTextField文本我使用是从文件加载如下:
NSString *path = [[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"];
NSAttributedString *as = [[NSAttributedString alloc] initWithPath:path documentAttributes:NULL];
[creditsLabel setAttributedStringValue:as];
[creditsLabel becomeFirstResponder];
在窗口中的超链接不能以蓝色下划线渲染,除非我第一次点击的NSTextField的地方,按照两个屏幕截图。
我怎样才能使这些超链接总是看起来像超链接?
这里的RTF:
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf250
{\fonttbl\f0\fnil\fcharset0 LucidaGrande;}
{\colortbl;\red255\green255\blue255;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural
\f0\fs24 \cf0 Copyright \'a9 2009-2010 Fully Functional Software.\
All rights reserved.\
\
BlazingStars is made possible by {\field{\*\fldinst{HYPERLINK "http://www.iterasi.net/openviewer.aspx?sqrlitid=p4mjpt7nl02tyjl08_ctaa"}}{\fldrslt DBPrefsWindowController}}, {\field{\*\fldinst{HYPERLINK "http://mattgemmell.com/source"}}{\fldrslt Image Crop}}, {\field{\*\fldinst{HYPERLINK "http://code.google.com/p/tesseract-ocr/"}}{\fldrslt Tesseract-OCR}}, {\field{\*\fldinst{HYPERLINK "http://andymatuschak.org/articles/2005/12/18/help-with-apple-help"}}{\fldrslt Andy's Help Toolkit}}, and {\field{\*\fldinst{HYPERLINK "http://wafflesoftware.net/shortcut/"}}{\fldrslt Shortcut Recorder}}.\
\
Includes icons from the BlueCons set by {\field{\*\fldinst{HYPERLINK "http://www.mouserunner.com"}}{\fldrslt Ken Saunders}}.}
结果 <子>(来源: pokercopilot.com )子>
结果 <子>(来源: pokercopilot.com )子>
解决方案
您可以得到的链接,看起来像样式他们在RTF这样的链接,但除非你能够编辑文本的属性和选择文本的文本字段不会处理点击。 (来源两个要求: QA1487 )我看到你你已经做了最后一部分,所以你现在需要做的是洒蓝色和下划线整个RTF上Diederik Hoogenboom的答复意见。
另一种解决方案是使用一个文本视图代替文本字段的
一个第三解决方案是使用 DSClickableTextField 。
其他提示
请确保您设置[creditsLabel setAllowsEditingTextAttributes: YES]
,否则链接将无法点击。
不隶属于 StackOverflow