Note that there are some explanatory texts on larger screens.

plurals
  1. POUILabels not overlaying correctly in UITextView
    primarykey
    data
    text
    <p>I'm trying to add syntax highlighting to my program.<br>I'm using this code to add highlights:</p> <pre><code>-(void)highlightWord:(NSString *)word: (UIColor *)color { int amount = textDisplay.text.length; NSString *newString = textDisplay.text; NSUInteger count = 0, length = amount; NSRange range = NSMakeRange(0, length); while(range.location != NSNotFound) { range = [textDisplay.text rangeOfString: word options:NSLiteralSearch range:range]; if(range.location != NSNotFound) { range = NSMakeRange(range.location + range.length, length - (range.location + range.length)); count++; } } while (count != 0) { count--; NSRange highlight = [newString rangeOfString:word]; newString = [textDisplay.text stringByReplacingCharactersInRange:highlight withString:@" "]; UILabel *view1 = [[UILabel alloc] initWithFrame:[self frameOfTextRange:highlight inTextView:textDisplay]]; view1.text = word; view1.textColor = color; view1.font = [UIFont fontWithName:@"System" size: 14.0]; view1.backgroundColor = [UIColor clearColor]; view1.textAlignment = UITextAlignmentLeft; [textDisplay addSubview:view1]; } } - (IBAction)highlighString:(id)sender { for (UIView *subview in [textDisplay subviews]){ if ([subview isKindOfClass:[UILabel class]]){ [subview removeFromSuperview]; } } [self highlightWord:@"test" :[UIColor blueColor]]; [self highlightWord:@"this" :[UIColor redColor]]; [self highlightWord:@"is" :[UIColor grayColor]]; [self highlightWord:@"a" :[UIColor greenColor]]; } @end </code></pre> <p>But this seems to cause a weird results:<br> <img src="https://i.stack.imgur.com/aJ34V.png" alt="..."> </p> <p><br>The desired result would be that it overlays to colored label seamlessly.</p>
    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.
 

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