gpt4 book ai didi

objective-c - 如何将 NSTextView 添加到 NSScrollView 中?

转载 作者:行者123 更新时间:2023-12-03 17:22:02 24 4
gpt4 key购买 nike

This document 。解释如何以编程方式将 NSTextview (可以滚动)添加到窗口。但是,如何以编程方式将 NSTextView 添加到 NSScrollView 中?

编辑:这是适用于 Windows 的代码。我希望能够以编程方式将 NSTextView 插入到我使用 Interface Builder 创建的 NSScrollView

-(IBAction)drawTextViews:(id)sender {

NSScrollView *scrollview = [[NSScrollView alloc]

initWithFrame:[[theWindow contentView] frame]];

NSSize contentSize = [scrollview contentSize];


NSTextView *theTextView = [[NSTextView alloc] initWithFrame:NSMakeRect(0, 0,

contentSize.width, contentSize.height)];

[theTextView setMinSize:NSMakeSize(0.0, contentSize.height)];

[theTextView setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];

[theTextView setVerticallyResizable:YES];

[theTextView setHorizontallyResizable:NO];

[theTextView setAutoresizingMask:NSViewWidthSizable];



[[theTextView textContainer]

setContainerSize:NSMakeSize(contentSize.width, FLT_MAX)];

[[theTextView textContainer] setWidthTracksTextView:YES];

[scrollview setDocumentView:theTextView];

[theWindow setContentView:scrollview];

[theWindow makeKeyAndOrderFront:nil];

[theWindow makeFirstResponder:theTextView];*/


[[theTextView enclosingScrollView] setHasHorizontalScroller:YES];

[theTextView setHorizontallyResizable:YES];

[theTextView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];

[[theTextView textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)];

[[theTextView textContainer] setWidthTracksTextView:NO];

最佳答案

正如评论中所指出的,您可以通过将 ScrollView 设置为文档 View 来实现 NSTextView。如果您希望 TextView 仅占据 ScrollView 的一小部分,则必须以另一种方式构造它。您想要实现的目标是什么?

关于objective-c - 如何将 NSTextView 添加到 NSScrollView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21493908/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com