Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I encountered the same problem for my application Zap-Guitar (No-Strings-Attached) where I allow users to type/paste/edit their own songs and the app highlights recognized chords.</p> <p>Yes it is true apple uses an html writer and parser to display the attributed text. A wonderful explanation of behind the scene can be found here: <a href="http://www.cocoanetics.com/2012/12/uitextview-caught-with-trousers-down/" rel="nofollow noreferrer">http://www.cocoanetics.com/2012/12/uitextview-caught-with-trousers-down/</a></p> <p>The only solution I found for this problem is not to use attributed text which is an overkill for syntax highlighting.</p> <p>Instead I reverted to the good old UITextView with plain text and added buttons to the text view where highlighted was needed. To compute the buttons frames I used this answer: <a href="https://stackoverflow.com/questions/10313689/how-to-find-position-or-get-rect-of-any-word-in-textview-and-place-buttons-over">How to find position or get rect of any word in textview and place buttons over that?</a></p> <p>This reduced CPU usage by 30% (give or take).</p> <p>Here is a handy category:</p> <pre><code>@implementation UITextView (WithButtons) - (CGRect)frameForTextRange:(NSRange)range { UITextPosition *beginning = self.beginningOfDocument; UITextPosition *start = [self positionFromPosition:beginning offset:range.location]; UITextPosition *end = [self positionFromPosition:start offset:range.length]; UITextRange *textRange = [self textRangeFromPosition:start toPosition:end]; CGRect rect = [self firstRectForRange:textRange]; return [self convertRect:rect fromView:self.textInputView]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload