Note that there are some explanatory texts on larger screens.

plurals
  1. POSequential Highlighting of a UILabels with sound clips
    text
    copied!<p>I have been searching for a answer for this issue for a while now, and haven't had any luck.</p> <p>Here is the issue: I have four UILabels, and sound clips to go with them. I want each label to show highlighted text when it's sound clip is played.</p> <p>The problem is that only the last label is gets highlighted when I test it on simulator.</p> <p>Here are some things that I've tried:</p> <pre><code>[self playSound:@"this"]; [thisLabel setTextColor:[UIColor orangeColor]]; sleep(1); [self playSound:@"is"]; [thisLabel setTextColor:[UIColor blackColor]]; [isLabel setTextColor:[UIColor orangeColor]]; [self playSound:@"a"]; [isLabel setTextColor:[UIColor blackColor]]; [aLabel setTextColor:[UIColor orangeColor]]; [self playSound:@"word"]; [aLabel setTextColor:[UIColor blackColor]]; [currentWord setTextColor:[UIColor orangeColor]]; </code></pre> <p>This is when I discovered that only the last label would show up highlighted when I tested it in the simulator.</p> <p>The next thing I tried is putting a call to this function at the end of t he playSound function.</p> <pre><code>- (void)shiftHighlight:(NSString *)word { UILabel *currentWord = [self currentWord]; UILabel *thisLabel = [self thisLabel]; UILabel *isLabel = [self isLabel]; UILabel *aLabel = [self aLabel]; if ([word isEqualToString:@"this"]) { [thisLabel setHighlighted:YES]; [isLabel setHighlighted:NO]; [aLabel setHighlighted:NO]; [currentWord setHighlighted:NO]; } else if ([word isEqualToString:@"is"]) { [isLabel setHighlighted:YES]; [thisLabel setHighlighted:NO]; [aLabel setHighlighted:NO]; [currentWord setHighlighted:NO]; } else if ([word isEqualToString:@"a"]) { [aLabel setHighlighted:YES]; [thisLabel setHighlighted:NO]; [isLabel setHighlighted:NO]; [currentWord setHighlighted:NO]; } else { [currentWord setHighlighted:YES]; [thisLabel setHighlighted:NO]; [isLabel setHighlighted:NO]; [aLabel setHighlighted:NO]; } } </code></pre> <p>With the color of the highlighted text set as orange elsewhere. This had the same effect as the first attempt.</p> <p>Most recently I tried putting successive calls to this function:</p> <pre><code>- (void)readSection:(NSString *)section { [self playSound:section]; [self shiftHighlight:section]; } </code></pre> <p>I've also tried something with NSTimers, but that got very confusing and it seemed like I was barking up the wrong tree with them.</p> <p>Behavior is enabled on all labels.</p> <p>So, if anyone has a solution for me, or can carefully explain how to use NSTimers for this issue, I'd her very thankful.</p>
 

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