Created
March 2, 2012 08:28
-
-
Save xinsight/1956762 to your computer and use it in GitHub Desktop.
Draw method for a playlist item that shows the playhead position. Uses path clipping to round corners on top and bottom. (2009)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define CORNER_RADIUS 10 | |
| - (void)drawRect:(CGRect)rect { | |
| CGContextRef context = UIGraphicsGetCurrentContext(); | |
| CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.5); // black | |
| if ([type isEqualToString:@"top"]) { // curved top | |
| CGContextBeginPath (context); | |
| CGContextMoveToPoint(context, 0, self.frame.size.height); // start: bottom-left | |
| CGContextAddArc (context, 0+CORNER_RADIUS, 0+CORNER_RADIUS, CORNER_RADIUS, M_PI, 3*M_PI/2, 0); // top-left | |
| CGContextAddArc (context, self.frame.size.width-CORNER_RADIUS, 0+CORNER_RADIUS, CORNER_RADIUS, 3*M_PI/2, 0, 0); // top-right | |
| CGContextAddLineToPoint(context, self.frame.size.width, self.frame.size.height); | |
| CGContextAddLineToPoint(context, 0, self.frame.size.height); | |
| CGContextClip(context); | |
| } else if ([type isEqualToString:@"bottom"]) { // curved bottom | |
| CGContextBeginPath (context); | |
| CGContextMoveToPoint(context, 0, self.frame.size.height); // start: bottom-left | |
| CGContextAddLineToPoint(context, 0, 0); | |
| CGContextAddLineToPoint(context, self.frame.size.width, 0); | |
| CGContextAddArc (context, self.frame.size.width-CORNER_RADIUS, self.frame.size.height-CORNER_RADIUS, CORNER_RADIUS, 0, M_PI/2, 0); // | |
| CGContextAddArc (context, 0+CORNER_RADIUS, self.frame.size.height-CORNER_RADIUS, CORNER_RADIUS, M_PI/2, M_PI, 0); | |
| CGContextClip(context); | |
| } else { | |
| // mid: NOOP // | |
| } | |
| CGContextFillRect(context, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)); | |
| // timeline // | |
| #define TIMELINE_MIN 4 | |
| if (isSelected) { | |
| CGRect frame = CGRectMake(0, 0, TIMELINE_MIN+(self.frame.size.width-TIMELINE_MIN)*playheadPosition, self.frame.size.height); | |
| CGContextSetRGBFillColor(context, 1.0, 0.49, 0.0, 0.9); | |
| CGContextFillRect(context, frame); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment