URL样式格式的NSTextField [英] NSTextField with URL-style format
问题描述
我一直试图让NSTextField识别URL,总的来说,我的代码可以工作. 我在此页面上按照Apple的说明进行了操作,以了解如何使用超链接FromString扩展NSAttributedString: withUrl和我的URL显示得很好.但是,当我单击链接时,文本格式会更改为一些较小的文本样式,可能还会更改为另一种字体.我下面有两个图像,其中两个NSLabel包含相同的URL.第一个显示其默认状态,第二个显示单击后的状态.
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.
http://i.stack.imgur.com/SAVa0.png
http://i.stack.imgur.com/rC4Hq.png
任何建议如何防止这种情况?
Any suggestions how to prevent this?
推荐答案
向您的NSAttributedString添加特定的NSFont
Add a specific NSFont to your NSAttributedString
[attrString addAttribute:@"NSFont" value:[NSFont systemFontOfSize:10.0] range:range];
这篇关于URL样式格式的NSTextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!