Albert
Albert

Reputation: 68240

modify TextEdit so that the NSTextView has transparent background. how?

I would like to have the NSTextView background and the window itself of TextEdit transparent but I'm not really sure how to do this. Some hints would be great.

Upvotes: 2

Views: 2044

Answers (3)

Matt Dunham
Matt Dunham

Reputation: 23

You need exactly two lines of code to achieve this:

[textField setBordered:NO];
[textField setDrawsBackground:NO];

Upvotes: 1

Francis McGrew
Francis McGrew

Reputation: 7272

Easy! The text view is created programmatically in the DocumentWindowController class, so just find the points where it is created (in the methods setHasMultiplePages: and addPage) and simply insert the code:

[textView setDrawsBackground:NO];

...to prevent the textView from drawing it's default white background. The light gray color you then see is being drawn by the text view's enclosing scrollview, which you can change in the DocumentWindow NIB.

EDIT: If you don't want the Scroll View to draw its background, uncheck "Draws Background," at which point you will just see the window's default gray background (drawn by it's content view)

Upvotes: 3

Albert
Albert

Reputation: 68240

This code seems to work:

[[self firstTextView] setDrawsBackground:NO];
[scrollView setDrawsBackground:NO];
[[self window] setBackgroundColor: [NSColor clearColor]];
[[self window] setOpaque:NO];

Upvotes: 1

Related Questions