标签: nstextview

使用NSData在NSTextView中设置Text

我有一个NSData实例,我从之前的应用程序运行中存储.我想使用这些数据设置NSTextView的文本.它是RTF,我无法弄清楚如何做到这一点.任何想法或建议?它需要使用代码而不是Interface Builder.

谢谢

macos xcode objective-c nstextview nsdata

4
推荐指数
1
解决办法
3478
查看次数

使用NSTextView对象打开/编辑位于应用程序包中的.txt文件

我想NSTextView在我的应用程序中添加一个对象,并添加一个操作,打开位于textView中应用程序包中的.txt文件.另外 - 我希望可以选择编辑和保存已编辑的文档而无需重命名.所以标准保存,不保存为.

处理这个问题的最佳方法是什么?

cocoa nstextview

4
推荐指数
1
解决办法
4525
查看次数

在应用启动时从桌面读取文本文件

我需要在启动时显示位于用户桌面上的文本文件的内容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)

macos cocoa objective-c text-files nstextview

4
推荐指数
1
解决办法
2546
查看次数

NSTextView结束编辑操作,如NSTextField

如何在NSTextView上检测结束编辑操作,就像在NSTextField上一样?我不能将其视为行动或其代表.

cocoa nstextview

4
推荐指数
1
解决办法
2758
查看次数

已调用 cursorUpdate,但未更新光标

我已经为此工作了几个小时,不知道出了什么问题。我想要一个按钮的自定义光标,它是 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)

cocoa cursor nstextview nscursor

4
推荐指数
1
解决办法
1313
查看次数

4
推荐指数
1
解决办法
3425
查看次数

不断增长的NSTableView行高

我在MacOSX应用程序中有一个基于视图的NSTableView,可以很好地构建数据.我想实现NSTableView的行高,它随着输入NSTextViews之一的数据内容而增长.我已经将NSTextView子类化为用户文本"增长",但问题是嵌入TableView中的字段会导致字段被剪裁.

有没有人对如何实现不断增长的行大小有任何建议?

macos cocoa nstextview nstableview

4
推荐指数
1
解决办法
2930
查看次数

在OS X v10.11中不推荐使用NSTextView的insertText方法.什么是替代品?

我在AppKit API Reference中看到该insertText方法在OS X v10.11中已弃用.我应该用什么作为替代品呢?

macos cocoa nstextview appkit

4
推荐指数
1
解决办法
2000
查看次数

子类化NSTextStorage中断列表编辑

我有一个标准的基本Mac应用程序NSTextView.我正在尝试实现并使用子类NSTextStorage,但即使是非常基本的实现也会破坏列表编辑行为:

  1. 我添加了一个带有两个项目的项目符号列表
  2. 我将该列表进一步复制并粘贴到文档中
  3. 在粘贴列表中按Enter键会中断最后一个列表项的格式.

这是一个快速视频:

NSTextStorage列表问题

两个问题:

  1. 粘贴列表的项目符号点使用较小的字体大小
  2. 在第二个列表项打破第三个项后按Enter键

当我不替换文本存储时,这工作正常.

这是我的代码:

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)

cocoa nstextview nstextstorage textkit

4
推荐指数
1
解决办法
149
查看次数

How to auto-expand height of NSTextView in SwiftUI?

How do I properly implement NSView constraints on the NSTextView below so it interacts with SwiftUI .frame()?

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 …

macos nstextview swiftui nsviewrepresentable

4
推荐指数
1
解决办法
4190
查看次数