MechMK1
MechMK1

Reputation: 3378

NSTextField with URL-style format

I've been trying to let an NSTextField recognize URL's and in general my code works. I followed Apple's instructions on this page on how to extend NSAttributedString with hyperlinkFromString:withUrl and my URL's get displayed quite well. However, when I click the link, the text-format changes into some smaller text style and probably another font. I've got two images below with two NSLabels containing the same URL's. The first shows their default state, the second how they look like after the first has been clicked.

https://i.sstatic.net/SAVa0.png
https://i.sstatic.net/rC4Hq.png

Any suggestions how to prevent this?

Upvotes: 3

Views: 829

Answers (2)

Christoph R
Christoph R

Reputation: 928

Add a specific NSFont to your NSAttributedString

[attrString addAttribute:@"NSFont" value:[NSFont systemFontOfSize:10.0] range:range];

Upvotes: 2

Francis McGrew
Francis McGrew

Reputation: 7272

Sigh... I tried to get this working myself and ended up having to use a NSTextView. Another option is the custom NSTextField code here which works quite well.

Upvotes: 0

Related Questions