Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
Hey all, bit of a stumper here. I'm attempting to draw a background behind an NSTextView, and I've run into a problem. I currently have an NSTextView as a subview of a NSView, the NSView drawing the background image. I set the NSTextView to *not* draw a background, and it looks great!

Until, that is, I enter more text. It "trails," and I understand the problem to be something about setting the ?NSClipView?'s copyWhileScrolling value to false, unavoidably, when setting the TextView to not draw a background. I've tried everything, from different background combinations, trying to redraw views on text changes, setting opacity values, and I can't find a solution.

Is there any *proper* way to give an NSTextView a background image? :)
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
One way I did this before was to subclass NSTextView and make it transparent:

Code:
- (void)awakeFromNib
{
	[self setDrawsBackground:NO];
	[(NSScrollView *)[self superview] setDrawsBackground:NO];
}

- (BOOL)isOpaque
{
	return NO;
}

Then I put a custom NSView, which draws the image, behind the text view. It worked great. I'm sure there is a better way to do this though (this is old code).

You can see an example of this in the demo of a commercial product I developed.
 

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
One way I did this before was to subclass NSTextView and make it transparent:

Code:
- (void)awakeFromNib
{
	[self setDrawsBackground:NO];
	[(NSScrollView *)[self superview] setDrawsBackground:NO];
}

- (BOOL)isOpaque
{
	return NO;
}

Then I put a custom NSView, which draws the image, behind the text view. It worked great. I'm sure there is a better way to do this though (this is old code).

You can see an example of this in the demo of a commercial product I developed.
I'm on my laptop right now, so I don't have my project with me, but I was just double-checking; the method you used didn't produce any weird text trailing effects?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
I had the image view redraw whenever the text view was scrolled or had its bounds changed.

Actually after looking at the code, I had the text view as a subview within the image view.
 

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
Got it working, turns out I was calling setDrawsBackground: on my subclassed NSView. Problem is, that method isn't implemented until later on down the hierarchy tree, so my subclass had no idea what I was asking it to do. :)

Strange though, it never displayed a warning, only an issue in the console, and the program continued to work fine!

Thanks for your help!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.