我有一个NSData实例,我从之前的应用程序运行中存储.我想使用这些数据设置NSTextView的文本.它是RTF,我无法弄清楚如何做到这一点.任何想法或建议?它需要使用代码而不是Interface Builder.
谢谢
我想NSTextView在我的应用程序中添加一个对象,并添加一个操作,打开位于textView中应用程序包中的.txt文件.另外 - 我希望可以选择编辑和保存已编辑的文档而无需重命名.所以标准保存,不保存为.
处理这个问题的最佳方法是什么?
我需要在启动时显示位于用户桌面上的文本文件的内容NSTextView.我的代码不起作用 - 是否偏离轨道?
NSError *err = nil;
NSString *filepath = @"~/Desktop/test.txt";
NSString *file = [NSString stringWithContentsOfFile:filepath
encoding:NSUTF8StringEncoding
error:&err];
if(!file) {
}
[textView setString:file];
Run Code Online (Sandbox Code Playgroud) 如何在NSTextView上检测结束编辑操作,就像在NSTextField上一样?我不能将其视为行动或其代表.
我已经为此工作了几个小时,不知道出了什么问题。我想要一个按钮的自定义光标,它是 NSTextView 的子视图,我添加了一个跟踪区域并在鼠标输入按钮时发送 cursorUpdate 消息。
每次鼠标进入跟踪区域时都会调用 cursorUpdate 方法。但光标停留在 IBeamCursor。
有任何想法吗?
Apple Docs 的参考:管理光标更新事件
- (void)cursorUpdate:(NSEvent *)event {
[[NSCursor arrowCursor] set];
}
- (void)myAddTrackingArea {
[self myRemoveTrackingArea];
NSTrackingAreaOptions trackingOptions = NSTrackingCursorUpdate | NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow;
_trackingArea = [[NSTrackingArea alloc] initWithRect: [self bounds] options: trackingOptions owner: self userInfo: nil];
[self addTrackingArea: _trackingArea];
}
- (void)myRemoveTrackingArea {
if (_trackingArea)
{
[self removeTrackingArea: _trackingArea];
_trackingArea = nil;
}
}
Run Code Online (Sandbox Code Playgroud) 我在MacOSX应用程序中有一个基于视图的NSTableView,可以很好地构建数据.我想实现NSTableView的行高,它随着输入NSTextViews之一的数据内容而增长.我已经将NSTextView子类化为用户文本"增长",但问题是嵌入TableView中的字段会导致字段被剪裁.
有没有人对如何实现不断增长的行大小有任何建议?
我在AppKit API Reference中看到该insertText方法在OS X v10.11中已弃用.我应该用什么作为替代品呢?
我有一个标准的基本Mac应用程序NSTextView.我正在尝试实现并使用子类NSTextStorage,但即使是非常基本的实现也会破坏列表编辑行为:
这是一个快速视频:
两个问题:
当我不替换文本存储时,这工作正常.
这是我的代码:
ViewController.swift
@IBOutlet var textView:NSTextView!
override func viewDidLoad() {
[...]
textView.layoutManager?.replaceTextStorage(TestTextStorage())
}
Run Code Online (Sandbox Code Playgroud)
TestTextStorage.swift
class TestTextStorage: NSTextStorage {
let backingStore = NSMutableAttributedString()
override var string: String {
return backingStore.string
}
override func attributes(at location: Int, effectiveRange range: NSRangePointer?) -> [NSAttributedString.Key:Any] {
return backingStore.attributes(at: location, effectiveRange: range)
}
override func replaceCharacters(in range: NSRange, with str: String) {
beginEditing()
backingStore.replaceCharacters(in: range, with:str)
edited(.editedCharacters, range: range,
changeInLength: (str as NSString).length - …Run Code Online (Sandbox Code Playgroud) Goal
An NSTextView that, upon new lines, expands its frame vertically to force a SwiftUI parent view to render again (i.e., expand a background panel that's under the text + push down other content in VStack). The parent view is already wrapped in a ScrollView. Since the SwiftUI TextEditor is ugly and under-featured, I'm guessing several others new to MacOS will wonder how …
nstextview ×10
cocoa ×8
macos ×6
objective-c ×3
appkit ×1
cursor ×1
nscursor ×1
nsdata ×1
nstableview ×1
swiftui ×1
text-files ×1
textkit ×1
xcode ×1