objective c - Draw bordered text efficiently in iOS -


I have a view with a custom drawRect method in which there are two text lines in the fixed width. This view is constantly being copied at a rate of about 16 timers per second, the state of the text and the content of the text varies from time to time. I need to be prepared in such a way that it is clearly visible in any background, and for that purpose I do the following:

  CGContextSetTextDrawingMode (ctx, kCGTextStroke); // Border mode [string dotau point: point to font: font]; CGContextSetTextDrawingMode (ctx, kCGTextFill); // text mode [string drawAtPoint: with point font: font];   

This code draws text in range mode with fixed line width, and then drages the text to the same position, but in the fill mode. In this way, I get a blue text with white border around each letter.

Except for the performance, it is absolutely satisfying for me to use the Time Profiler that I have seen that approximately 70% of the spent time spent on drawing the whole scene is used to execute the text on drawing execution. But drawing in frame mode takes only 3% of the entire view drawing time. I think it is not able to consider the frequency of reprint of the scene.

Does anybody know how to attract text with a border around each letter more efficiently?

two options:

  1. Use shadows instead of drawing outline : CGContextSetShadowWithColor
  2. Cache the string's image and it's outline using CGLAir: CGLayerCreateWithContext

    Explanation for 2:

    The drawing text is highly optimized for the standard case where the letters are filled with just one color. The individual glyph (letter) is not translated from the framework of each time, instead, glyphs are pulled in buffer images only once, which are cached and resized.

    Drawing Drawing Seldom Perhaps there is no caching of glyph or other optimization for this mode. So this idea is to caching itself: Drag the entire string into an image, place that image around and draw it instead of your drawRect: method.

    There are several options to do this:

    1. Use one
    2. Use

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -