0

I have a NSTextView that I am using to display a timer. This timer updates every second counting down to 00:00. When the timer updates the string for the NSTextView, the NSTextView acts as if it redraws but uses its parents views background for its own background.

My NSTextView has a clear background color and has been set not to draw its background. Its parent view draws a 3 part image for its own background. Below is the code for the NSTextView.

_timerLabel = [[NSTextView alloc] init];
[self.timerLabel setSelectable:NO];
[self.timerLabel setEditable:NO];
self.timerLabel.font = fontLoaded ? [NSFont fontWithName:@"DS-Digital" size:26.0f] : [NSFont fontWithName:@"Lucida Grande" size:26.0f];
self.timerLabel.textColor = [NSColor colorWithCalibratedRed:(50.0f/255.0f) green:(50.0f/255.0f) blue:(50.0f/255.0f) alpha:1.0f];
self.timerLabel.backgroundColor = [NSColor clearColor];
[self.timerLabel setDrawsBackground:NO];
[self.timerLabel setAllowsDocumentBackgroundColorChange:NO];
[self.timerLabel setAlignment:NSCenterTextAlignment];
self.timerLabel.string = @"5:11";
[self addSubview:self.timerLabel];

Any ides why this would be happening? I have tried everything I could think of or find in the apple documents and nothing has solved my issue. Any help would be greatly appreciated.

Before updating the text in the NSTextView https://www.dropbox.com/s/za3twd8hb7r1apr/Screen%20Shot%202013-04-10%20at%205.37.10%20PM.png

After updating the text in the NSTextView https://www.dropbox.com/s/p0bsk63o8yweyqs/Screen%20Shot%202013-04-10%20at%205.37.28%20PM.png

1 Answers1

0

I figured out what was happening and thought I share in case anyone else gets stuck with the same issue.

When updating the text for the NSTextView (can be an NSTextField too), the drawRect function gets called with the rect for the NSTextView that was updated.

In my case, my draw rect was drawing a 3 part image for the background of my NSView to the supplied rect in the drawRect function. Since the rect was the rect of the NSTextView after and updated to its string, this would redraw my background image for the size of the NSTextView.

Currently the only solution I have been able to come up with is to always draw my 3 part image for the bounds of my NSView.

Hope that makes since.