Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing text color of NSTextView in Interface Builder won't work

I can set background color for NSTextView, also insertion color, but when I try to change text color it just doesn't work.

I can set the color programmatically before each insert of text, but I'm probably doing something wrong, since Interface Builder offers this options.

Here's what my inspector looks like:

alt text

like image 791
Vojto Avatar asked Sep 04 '10 16:09

Vojto


2 Answers

Here is what I have tried below and the results I've found which led me to my conclusion.

  1. (a)Add NSTextView (b)change color. Result: Does not work enter image description here

  2. (a)Add NSTextView (b)then change the text (c) press enter because it failed when i didnt press enter (d) then change the color. Result: Works enter image description here

If the text property of the NSTextView is not set in Interface-Builder, it does not seem to save the text color property. Thus causing the app to select the default color upon launch. The other properties such as Background-Color and Insertion color however, are saved. This leads me to think this is a bug in interface builder.

As a workaround, you can leave single blank space in the text box and the set your color in interface builder, but this might not be favorable for you depending on what you wish to do with the NSTextView

like image 199
Just a coder Avatar answered Oct 19 '22 12:10

Just a coder


As far as I can see - there's a bug in appkit as of (10.10) when the text is not initialized. This hack got me out of 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]];
}
like image 39
johndpope Avatar answered Oct 19 '22 11:10

johndpope