How to highlight CoreText with changing the color of the backlight?

I have a subclass of UIView that implements code to draw a CoreText. In the application, this UIView is drawn inside the UIScrollView. Here is the code I'm currently using in drawRect: for rendering NSAttributedString:

CGContextRef context = UIGraphicsGetCurrentContext();

float viewHeight = self.bounds.size.height;
CGContextTranslateCTM(context, 0, viewHeight);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0, 1.0));

CGMutablePathRef path = CGPathCreateMutable();
CGRect bounds = CGRectMake(PADDING_LEFT, -PADDING_TOP, self.bounds.size.width-20.0, self.bounds.size.height);
CGPathAddRect(path, NULL, bounds);

CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFMutableAttributedStringRef)attrString);
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL);
CFRelease(framesetter);
CFRelease(path);
CTFrameDraw(frame, context);

In my NSAttributedString, I have specific text attributes for colored text.

I need help, conceptually, how should this be achieved? I am confused by all the different ways of drawing frames, layers, etc. I tried to look through several books and other resources, but I feel that I am missing some basic things.

Here are my requirements:

  • The main points, obviously, should be redrawn in a new place when changing orientation.
  • Color highlighting should be changed programmatically based on individual highlighting.
  • , CoreText UIView, .
  • Rects , , , CTLine.
  • , UIMenuController CoreText, , CoreText UIView?

.

:

UIView UIScrollView, . UIViews . "", CoreText. . , CoreText , . , drawRect - ?

:

  • UIView UIScrollView, ? UIView NSArray?
  • CoreText UIView, , UIView ? , ?
  • , , CoreText UIView UIMenuController, CoreText UIView?

:

https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML

, , , . , CoreText, , . , , . CoreGraphics, CoreAnimation CoreText.

:

- NSRange

Rect . , .

UPDATE

. , , , ...

  • UIView UIScrollView .
  • UIView CoreTextView. CoreTextView, , .
  • CoreTextView UIScrollView. , UIView CoreTextView.
  • drawRect: CoreTextView CoreText. .
  • NSRange CGRect .
  • CGRect UIView. UIView UIView. NSArray, .

drawRect , . , . :

  • UIViewController setNeedsDisplay CoreTextView, , . , ViewController, .
  • UIViews UIView, drawRect , , , - .
  • , , .
+5
1

. , , , , , , .

, , Core Text CALayer. , . . , . "", backgroundColor frame , .

+2

All Articles