NSTextView text color change in Interface Builder will not work

I can set the background color for the NSTextView as well as the insert color, but when I try to change the color of the text, it just doesn't work.

I can set the color programmatically before each text insertion, but I'm probably doing something wrong, as Interface Builder offers these options.

This is what my inspector looks like:

alt text

+6
cocoa interface-builder
source share
2 answers

Here is what I tried below, and the results that I found led me to my conclusion.

  • (a) Add an NSTextView (b) change the color. Result: Not working enter image description here

  • (a) Add an NSTextView (b), then change the text (c) press enter because it failed when I did not press enter (d) and then changed the color. Result: Works enter image description here

If the text property for NSTextView is not set in Interface-Builder, it does not seem to retain the text color property. Thus, the application launches the default color selection at startup. However, other properties are retained, such as background color and insert color. This makes me think this is a bug in the interface builder.

As a workaround, you can leave one empty space in the text box and set the color in the interface builder, but this may not be beneficial for you depending on what you want to do with NSTextView

+4
source share

As far as I can see, there is an error in appkit from (10.10) when the text is not initialized. This hack caused me trouble.

 NSTextView *tf = tf.delegate = self; - (void)textDidChange:(NSNotification *)aNotification { NSLog(@"notificaiton:%@",aNotification); NSMTextView *tv = (NSMTextView *)[aNotification object]; [tv setTextColor:[NSColor whiteColor]]; [[tv textStorage] setFont:[NSFont systemFontOfSize:30]]; } 
0
source share

All Articles