0

I'm trying to find an effecient way of dynamically displaying text in an NSTextField and slowly filling it with a colour. Would the best way of doing this be by creating two labels on top of eachother, one with a black colour and one with say pink... And then applying a mask to the top layer and gradually adjusting it's size?

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140

1 Answers1

0

Would the best way of doing this be by creating two labels on top of eachother, one with a black colour and one with say pink... And then applying a mask to the top layer and gradually adjusting it's size?

YES

Here is the running model of same:

Few codes here:

-(void)fillColor{
    NSRect frame=NSMakeRect(self.label.frame.origin.x, self.label.frame.origin.y, self.label.frame.size.width+1.0, self.label.frame.size.height);
    self.label.frame=frame;
    if (self.label.frame.size.width>=self.labelWithText.frame.size.width) {
        [self.timer invalidate];
        self.timer=nil;
    }
}

-(IBAction)button:(id)sender;{
    [self.label setStringValue:@"aaaaaa"];
    [self.label setDrawsBackground:YES];
    [self.label setBackgroundColor:[NSColor redColor]];
    self.timer=[NSTimer scheduledTimerWithTimeInterval:.1f target:self selector:@selector(fillColor) userInfo:nil repeats:YES];
}
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140