Created
October 5, 2012 19:47
-
-
Save jonathansousa/3841945 to your computer and use it in GitHub Desktop.
iOS DrawRect Code
This file contains 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
- (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