NSTextField (Label) Attribute text: select

I have an NSTextField Label that attributed the text in it. Color and size are different from the default values. (The text is slightly larger and green). Now I need to select the text in the shortcut to click the hyperlinks embedded in the attribute text. This works great; however, when you select text, the text format returns to the default values ​​(smaller black font).

Is there a way to stop this behavior so that my style persists when the user clicks (selects text) on a shortcut?

EDIT: for the record, I have another shortcut with white text that does not change color when selected, only size.

+5
source share
2 answers

Good. After further research on why white color “sticks” and why green wasn’t, I found that any text attributes set in Interface Builder do not remain after selection.

Therefore, the solution is to always call setAttributedStringValue:using NSAttributedString, which has the attributes that you want to make sure when selecting on your label.

+2
source

I ran into the same problem. The accepted answer, unfortunately, did not correct. My text style still changed when I selected, even if I installed attributedStringValue.

Thanks to the answer in this question , I was able to partially solve the problem by calling:

label.allowsEditingTextAttributes = true

0
source

All Articles