简体   繁体   English

修改TextEdit,以使NSTextView具有透明背景。 怎么样?

[英]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. 我想让NSTextView背景和TextEdit的窗口本身透明,但是我不确定如何做到这一点。 Some hints would be great. 一些提示会很棒。

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: 文本视图是在DocumentWindowController类中以编程方式创建的,因此只需找到其创建位置(在setHasMultiplePages:和addPage方法中),然后只需插入代码即可:

[textView setDrawsBackground:NO];

...to prevent the textView from drawing it's default white background. ...以防止textView绘制默认的白色背景。 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. 您随后看到的浅灰色将由文本视图的封闭滚动视图绘制,您可以在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) 编辑:如果您不希望滚动视图绘制其背景,请取消选中“绘制背景”,此时您将只看到窗口的默认灰色背景(由其内容视图绘制)

This code seems to work: 这段代码似乎有效:

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

You need exactly two lines of code to achieve this: 您只需要两行代码即可实现此目的:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM