NSTextView 背景未适当调整大小
我在 NSScrollView 中有一个 NSTextView 。滚动视图具有高度和宽度的自动调整大小蒙版,因此它会随着其所在的窗口而改变大小。
文本视图的设置方式与苹果文档推荐的方式大致相同此处。
但无论我在文本视图上进行什么设置,我都无法使背景颜色与滚动视图一起调整大小。
这是我正在处理的图片:
宽度有效,但高度无效。
这是我针对这张图片的文本视图的设置代码:
NSTextView *view = [[NSTextView alloc] initWithFrame:NSMakeRect(0, 0, scrollview.contentSize.width, scrollview.contentSize.height) textContainer:textContainer];
[view setMinSize:NSMakeSize(0.0, scrollview.contentSize.height)];
[view setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
[view setVerticallyResizable:YES];
[view setHorizontallyResizable:NO];
[view setAllowsDocumentBackgroundColorChange:YES];
[view setDrawsBackground:YES];
[view setAutomaticLinkDetectionEnabled:YES];
[view setAutoresizingMask:NSViewWidthSizable];
I have an NSTextView inside an NSScrollView. The scroll view has the auto resize masks for height and width, so it changes size with the window it's in.
The text view is set up much in the way the apple documentation recommends here.
But no matter what settings I put on the text view, I cannot get the background color to resize along with the scroll view.
Here's a picture of what I'm dealing with:
The width works, but not the height.
Here's my setup code for the textview as it is for this picture:
NSTextView *view = [[NSTextView alloc] initWithFrame:NSMakeRect(0, 0, scrollview.contentSize.width, scrollview.contentSize.height) textContainer:textContainer];
[view setMinSize:NSMakeSize(0.0, scrollview.contentSize.height)];
[view setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
[view setVerticallyResizable:YES];
[view setHorizontallyResizable:NO];
[view setAllowsDocumentBackgroundColorChange:YES];
[view setDrawsBackground:YES];
[view setAutomaticLinkDetectionEnabled:YES];
[view setAutoresizingMask:NSViewWidthSizable];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
白色背景色不是
NSTextView
的背景色,而是其封闭的NSScrollView
的背景色。要更改它,请在 Interface Builder/Xcode 4 中选择 NSScrollView。或者,要以编程方式执行此操作,请使用
-[NSView encosingScrollView]
:The white background colour isn’t that of the
NSTextView
, but rather that of its enclosingNSScrollView
.To change it, either select the NSScrollView in Interface Builder/Xcode 4. Or, to do it programmatically, use
-[NSView encosingScrollView]
: