NSTextField(标签)属性文本:选择 [英] NSTextField (Label) Attributed Text: Select

查看:388
本文介绍了NSTextField(标签)属性文本:选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSTextField标签,其中包含属性文本。颜色和大小与默认值不同。 (文本稍大一些,呈绿色)现在,我需要能够选择标签中的文本,以便单击属性文本中嵌入的超链接。这很好用;但是,当选择文本时,文本的格式将恢复为默认值(较小的黑色字体)。

I have a NSTextField Label that has attributed text in it. The color and size are different from the defaults. (The text is a bit larger and green) Now, I need to be able to select the text in the label so as the click the hyperlinks embedded in the attributed text. This works fine; however, when selecting the text the format of the text reverts back to the defaults (a smaller, black font).

是否仍然可以阻止此行为,以便我进行样式设置当用户单击(选择文本)标签时保留了该标签吗?

Is there anyway to stop this behavior so that my styling is preserved when the user clicks (selects text) on a Label?

编辑:为了记录,我有另一个带有白色文本的标签,该标签在选定时不会改变颜色,

For the record, I have another label with white text that does not change color when selected, only size.

推荐答案

好的。在进一步研究了白色为什么发粘以及为什么绿色没有发粘之后,我发现在选择之后,Interface Builder中设置的所有文本属性都不会保留。

Okay. After further research as to why the white color was 'sticking' and why the green was not, I discovered that any text attributes set in Interface Builder do not stay after selection.

因此,解决方案是始终调用带有NSAttributedString的 setAttributedStringValue:,该属性具有要确保在选择标签时停留的属性。

Therefore, the solution is to always call setAttributedStringValue: with an NSAttributedString that has attributes that you want to make sure stay during selection on your label.

这篇关于NSTextField(标签)属性文本:选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆