English 中文(简体)
缩略语
原标题:NSTextView highlight

In the product I am building for Mac OSX,I need to support 10.5,10.6 and 10.7. I am using NSTextView as an editor. I use it to display both text and images. I have a requirement about highlighting. This has to work exactly like MS Word. In MS Word you can select a range and change it to yellow color.

我也使用了MarkedTextAttributes:但这不是用于网上图像。 因此,我尝试利用LayoutManager,确定背景,但似乎也没有工作。

还有一点是强调这一点,因此,如果我选择同样的案文并再次强调,就应当无动于衷。 为此,我正在把所有NSRange列入清单,并检查它是否得到强调。 我认为,我做了一些错误的事情。 因此,我试图获得NSRect,然后适用肤色可能是?

最佳回答

在国家航空航天局的协助下,确定这一范围的背景:

NSMutableAttributedString *mattrstg = [textView textStorage];
[mattrstg addAttribute:NSBackgroundColorAttributeName value:colorHighlighter range:range];

现有的属性将是你对已经强调的和已经强调的 t的记录。 因此,为了分析你可以做的强调

[mattrstg enumerateAttribute:NSBackgroundColorAttributeName 
          inRange:rangeToChange 
          options:0 usingBlock:^(id value, NSRange range, BOOL *stop) { 
              if (value) {
                  [mattrstg removeAttribute:NSBackgroundColorAttributeName range:range]; 
              } else {
                  [mattrstg addAttribute:NSBackgroundColorAttributeName value:colorHighlighter range:range]; 
              }
          }];
问题回答

暂无回答




相关问题
Taking picture with QTCaptureView

Is it possible to simply take a picture and save it somewhere using a QTCaptureView and Apple s built-in iSight? I ve seen lots of tutorials on recording video but none on simply taking a picture. Any ...

Controlling OSX windows

I m trying to control windows of a foreign OSX applications from my application. I d like to 1. move the windows on the screen 2. resize the windows on the screen 3. change the currently active window ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

How to get a flash url in a webpage using a webframe?

As we know , When we load frame from webpage of safari, we will invoke the delegate methods of webkit informal protocol(WebFrameLoadDelegate): webView:didStartProvisionalLoadForFrame: webView:...

热门标签