Skip to content

Instantly share code, notes, and snippets.

@jonathansousa
Created October 5, 2012 19:47
Show Gist options
  • Save jonathansousa/3841945 to your computer and use it in GitHub Desktop.
Save jonathansousa/3841945 to your computer and use it in GitHub Desktop.
iOS DrawRect Code
- (void)drawRect:(CGRect)rect {
// CGRect bounds = [self bounds];
CGContextRef ref = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ref, 1.0);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGFloat components[] = {0.4, 0.4, 0.4, 1.0};
CGColorRef color = CGColorCreate(colorspace, components);
CGContextSetStrokeColorWithColor(ref, color);
CGContextMoveToPoint(ref, 111, 5);
CGContextAddLineToPoint(ref, 282, 5);
CGContextMoveToPoint(ref, 111, 2);
CGContextAddLineToPoint(ref, 111, 8);
CGContextMoveToPoint(ref, 282, 2);
CGContextAddLineToPoint(ref, 282, 8);
if ([self.minValue integerValue] < 0) {
NSInteger position = 0;
position += abs([self.minValue integerValue]);
float percentage = position / [self.spanValue floatValue];
float pixelsLeft = percentage * (282 - 111);
CGContextMoveToPoint(ref, pixelsLeft + 111, 2);
CGContextAddLineToPoint(ref, pixelsLeft + 111, 8);
}
CGContextStrokePath(ref);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment