5

NSTextField で使用するテキストは、次のようにファイルから読み込まれます。

NSString *path = [[NSBundle mainBundle] pathForResource:@"Credits"  ofType:@"rtf"];
NSAttributedString *as = [[NSAttributedString alloc] initWithPath:path documentAttributes:NULL];
[creditsLabel setAttributedStringValue:as];
[creditsLabel becomeFirstResponder];

2 つのスクリーンショットのように、最初に 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 )

4

2 に答える 2

7

RTF でそのようにスタイルを設定することにより、リンクをリンクのように見せることができますが、テキスト属性の編集とテキストの選択を有効にしない限り、テキスト フィールドはクリックを処理しません。(両方の主張のソース: QA1487 .) Diederik Hoogenboom の回答に対するコメントで、最後の部分は既に完了していることがわかります。RTF 全体に青を振りかけ、下線を引くだけです。

もう 1 つの解決策は、テキスト フィールドの代わりにテキスト ビューを使用することです。

3 番目の解決策は、 DSClickableTextFieldを使用することです。

于 2010-01-26T09:33:14.500 に答える
2

を必ず設定してください[creditsLabel setAllowsEditingTextAttributes: YES]。そうしないと、リンクをクリックできなくなります。

于 2010-01-25T16:57:12.293 に答える