Make URL in NSTextFieldCell Client

There are two parts to this question:

(1) How to determine the URLs in a given text?

(2) How to make an interactive part of the text in a cell in a text field (as a table)? I would like the URLs to open in the default web browser when I click on them.

+3
source share
2 answers

To make URLs interactive, check out this Apple tutorial: Embed Hyperlinks in NSTextField and NSTextView

In the first part, are you married to using NSTextField? The reason is that NSTextView provides this automatically (this is just a checkbox in IB). Otherwise, check fooobar.com/questions/894888 / ... .

, , .

+6

this, ,

NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:@"Google"];
[str addAttribute: NSLinkAttributeName value: @"http://www.google.com" range: NSMakeRange(0, str.length)];
yourTextView.attributedText = str;
+1

Source: https://habr.com/ru/post/1792384/


All Articles