问候,
我有一个NSTextView,有大量的文本.然而,每当我滚动时,视图都没有正确更新.有些工件保留在视图的顶部或底部.看来该视图不会经常刷新自己.如果我滚动得非常慢,视图会正确更新.如果我为视图添加边框一切都很完美,那么无边框视图就会出现问题.这是截图的链接:
http://img216.imageshack.us/img216/8193/picture13s.png
谢谢
我有一个NSTextView并要求插入点的坐标在用户交互时显示那里的视图.
有一个函数可以从NSPoint获取字符索引.我想知道是否有任何简单的方法可以做相反的事情?
谢谢你的帮助!
我怎样才能设置NSTextView为NSAttributedString?我不想使用textConainer,我试过:
[myTextView insertText:myMutableAttributedString];
Run Code Online (Sandbox Code Playgroud)
但它不起作用.什么都没发生......甚至没有警告或运行时错误.任何帮助,将不胜感激.
我在NSView中有一个NSTextView,不可编辑,不可选.我需要NSView在单击文本视图时接收单击事件 - 基本上我需要单击事件来表现为文本视图甚至不存在.显然我会使用
textView:clickedOnCell:inRect:atIndex:
Run Code Online (Sandbox Code Playgroud)
文本视图委托方法,但我需要捕获click事件,以检测双击和类似的事情.
我正在寻找一种可靠的技术来在NSTextView中进行简单的字符串格式化(粗体,斜体,...).文本解析几乎是用正则表达式完成的,但现在我需要应用字体特征并改变大小.
关于如何使文本变粗的一些代码片段
[[textView textStorage] beginEditing];
[[textView textStorage] applyFontTraits:NSFontBoldTrait range:range];
[[textView textStorage] endEditing];
Run Code Online (Sandbox Code Playgroud)
这和尺寸也随之改变
[[textView textStorage] beginEditing];
NSFont* font = [[textView textStorage] attribute:NSFontAttributeName atIndex:range.location effectiveRange:nil];
NSFont* newFont = [NSFont fontWithName:[font familyName]
size:[font pointSize] + size];
[[textView textStorage] addAttribute:NSFontAttributeName
value:newFont
range:range];
[[textView textStorage] endEditing];
Run Code Online (Sandbox Code Playgroud)
工作良好.我现在唯一的问题是,在某些情况下,当我键入新字符时,默认情况下这些字符是粗体或斜体,即使我没有将属性应用于它们.
我是否需要重置与东西setTypingAttributes的NSTextView还是我只是错过了一些东西?
好的,这就是我想要的:
NSTextViewNSRange在光标位置获取"当前"字(作为?)(如何确定?)我不确定如何解决这个问题:我的意思是我的主要关注点是获取当前位置NSTextView并获得关键点(我知道一些Text插件支持这一点,但我不确定原始NSTextView实现... )
那有内置功能吗?或者,如果没有,任何想法?
更新: 光标位置(已解决)
NSInteger insertionPoint = [[[myTextView selectedRanges] objectAtIndex:0] rangeValue].location;
Run Code Online (Sandbox Code Playgroud)
现在,仍在尝试找到指定基础单词的解决方法......
在我的应用程序中,我想在层支持的NSTextView中提供文本缩放,如Apple的TextEdit.我使用它的ScalingScrollView模拟.另外我需要创建一些CALayer叠加self.window.contentView.一切都好,直到我做[self.window.contentView setWantsLayer:YES].
之前 [setWantsLayer:YES]

后 [setWantsLayer:YES]

我没有任何想法如何解决这个问题.
我有一堆NSTextViews,我想分享一个选择.我基本上希望它的行为类似于在网页上选择文本,其中有多个文本视图,但您可以拖动以顺序选择其中的文本.
我发现这个文档声明可以让多个NSTextContainer对象共享一个NSLayoutManager,从而共享选择.这是我想要的一半,除了一个人NSLayoutManager只能有一个NSTextStorage对象的事实.我希望每个文本视图都有自己的文本视图,NSTextStorage以便每个文本视图都有自己的文本,但我仍然希望能够通过一次拖动选择多个文本视图中的文本.这可能吗?
cocoa objective-c nslayoutmanager nstextview nstextcontainer
我的目标是创建一个类似于Goole Docs文本编辑器的视图,并在文本后面有注释突出显示有注释.

我的解决方案是NSScrollView包含一个NSView(设置为文档视图),滚动并包含NSTextView文本和其他NSView将成为高亮的文本.
为了使其工作,NSTextView必须将其大小视为直接属于NSScrollView.但是,我无法做出NSTextView这种行为.
我对布局的代码是:
LatinViewController:的loadView()
...
let latinView = LatinView()
latinView.autoresizingMask = [.ViewWidthSizable]
latinView.wantsLayer = true
latinView.layer?.backgroundColor = Theme.greenColor().CGColor
self.latinView = latinView
scrollView.documentView = latinView
...
Run Code Online (Sandbox Code Playgroud)
拉丁语查看:的init()
...
let textView = LatinTextView()
textView.translatesAutoresizingMaskIntoConstraints = false
textView.string = "Long string..."
self.addSubview(textView)
self.textView = textView
self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[text]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["text": textView]))
self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[text]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["text": textView]))
...
Run Code Online (Sandbox Code Playgroud)
LatinTextView:的init()
...
self.minSize = NSMakeSize(0, …Run Code Online (Sandbox Code Playgroud) 我想实现与[[NSFontManager sharedFontManager] addFontTrait:(nullable id)sender]仅使用我的代码相同的事情
医生说
This action method causes the receiver to send its action
message up the responder chain.
By default, the action message is changeFont:.
When a responder replies by providing a font to convert in
a convertFont: message, the receiver converts the font by
adding the trait specified by sender. This trait is determined
by sending a tag message to sender and interpreting it as a font
trait mask for a convertFont:toHaveTrait: message.
Run Code Online (Sandbox Code Playgroud)
所以我试过
NSFontManager …Run Code Online (Sandbox Code Playgroud) cocoa ×10
nstextview ×10
objective-c ×3
artifacts ×1
calayer ×1
macos ×1
nsscrollview ×1
nstextfield ×1
nsview ×1
swift ×1