text highlighting with CALayer and NSTextVew
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