Skip to content

Instantly share code, notes, and snippets.

@mindbrix
Created July 8, 2013 11:48
Show Gist options
  • Save mindbrix/5948093 to your computer and use it in GitHub Desktop.
Save mindbrix/5948093 to your computer and use it in GitHub Desktop.
How to draw rapidly refreshed string labels performantly using GCD.
-(void)drawTimecodeUsingGCD
{
if( dispatch_semaphore_wait( _timecodeSemaphore, DISPATCH_TIME_NOW ) != 0 )
{
return;
}
dispatch_async( _timecodeQueue, ^()
{
float fontSize = ceilf( self.scrubberSize * 0.425f );
UIFont *font = [ UIFont fontWithName:@"Courier" size:fontSize ];
CGSize labelSize = [ _avPlayerView.timecode sizeWithFont:font ];
UIGraphicsBeginImageContextWithOptions( labelSize, NO, [ UIScreen mainScreen ].scale );
[[ UIColor blackColor ] set ];
[ _avPlayerView.timecode drawAtPoint:CGPointZero withFont:font ];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
dispatch_async( dispatch_get_main_queue(), ^()
{
self.timecodeImageView.image = image;
self.timecodeImageView.frame = CGRectMake( 0.0f, 0.0f, labelSize.width + self.thumbnailPadding, labelSize.height + self.thumbnailPadding );
[ self.timecodeImageView centreHorizontally ];
self.timecodeImageView.hidden = self.timecodeHidden;
dispatch_semaphore_signal( _timecodeSemaphore );
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment