• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
text highlighting with CALayer and NSTextVew
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

text highlighting with CALayer and NSTextVew


  • Subject: text highlighting with CALayer and NSTextVew
  • From: Koen van der Drift <email@hidden>
  • Date: Wed, 22 Aug 2012 20:21:35 -0400

I'd like to add some custom text highlighting to my NSTextView, so I added the following code to the NSTextView init method:

    CALayer *aLayer = [CALayer layer];
    [self setWantsLayer: YES];
    [self setLayer: aLayer];


Then I add the highlighting for a particular text range (aRange):

         self.layer.backgroundColor = CGColorCreateGenericRGB (0.2, 0.2, 0.1, 1.0);
         self.layer.frame = [self.layoutManager boundingRectForGlyphRange: aRange inTextContainer: self.textContainer];

But it looks all garbled for the while view, not for the range, and I see the Xcode window text behind it.

What should I do to make this work?

attributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSColor redColor, NSBackgroundColorAttributeName, nil];
[self layoutManager] addTemporaryAttributes: attributes forCharacterRange: aRange];  works, but I'd like to have some more control on how the text highlighting is drawn.


- Koen.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: text highlighting with CALayer and NSTextVew
      • From: Kyle Sluder <email@hidden>
    • Re: text highlighting with CALayer and NSTextVew
      • From: Koen van der Drift <email@hidden>
  • Prev by Date: Re: Sandboxing die.die.die
  • Next by Date: Re: Sandboxing die.die.die
  • Previous by thread: iOS 5.0.1 vs. 5.1.x and MapKit Overlays.
  • Next by thread: Re: text highlighting with CALayer and NSTextVew
  • Index(es):
    • Date
    • Thread