I am building an application in iphone for that I need to draw a 7-bit segment display which will display the numbers that is being fed by the user.I am using CGPath and CGcontext.
I have drawn 7-bit segment as the no in digital clock.But, I am not getting the way to display the no given By user. To draw a 7-bit segment display, i have done..
CGContextRef context = UIGraphicsGetCurrentContext();
CGLineCap cap =kCGLineCapRound;
center = CGPointMake(120, 130.0);
CGContextSetRGBStrokeColor(context, 0.5, 0.0, 1.0, 0.5);
path = CGPathCreateMutable();
CGContextSetLineWidth(context, 08.0);
CGContextSetLineCap(context, cap);
CGPoint aOnePoint=CGPointMake(center.x ,center.y);
CGPoint aTwoPoint=CGPointMake(center.x ,center.y+30);
CGPoint points[]= {aOnePoint,aTwoPoint};
CGAffineTransform translation1 = CGAffineTransformMakeTranslation(0, 30);
CGAffineTransform translation2 = CGAffineTransformTranslate(translation1, 0, 42);
CGAffineTransform translation3 = CGAffineTransformTranslate(translation1, 42,0);
CGAffineTransform translation4 = CGAffineTransformTranslate(translation1, 42, 42);
CGAffineTransform translation7 = CGAffineTransformMakeTranslation(-270, 0);
CGAffineTransform translation5 = CGAffineTransformMakeRotation(-M_PI/2.0);
CGAffineTransform translation8 = CGAffineTransformMakeTranslation(-4, +3);
CGAffineTransform translation6 = CGAffineTransformConcat(CGAffineTransformConcat(translation7, translation5),translation8);
CGAffineTransform translation9 = CGAffineTransformTranslate(translation6, -44, 0);
CGAffineTransform translation10 = CGAffineTransformTranslate(translation6,-86, 0);
CGPathAddLines(path, &translation1 ,points,2);
CGPathAddLines(path, &translation2,points,2);
CGPathAddLines(path, &translation3 ,points,2);
CGPathAddLines(path, &translation4 ,points,2);
CGPathAddLines(path, &translation6 ,points,2);
CGPathAddLines(path, &translation9 ,points,2);
CGPathAddLines(path, &translation10 ,points,2);
CGContextBeginPath(context);
CGContextAddPath(context, path);
CGPathRelease(path);
CGContextStrokePath(context);
CGContextSaveGState(context);
CGContextClosePath(context);
Any help will be appreciated.
Do you really need to draw it? I’m sure 10 images, one for each numeral, would be much more satisfying.
Edit from comment:
If you name your images
0.png1.png2.pngetc., you can use the integer value entered by the user to change the displayed image(s) very quickly. If you’re worried about wasting disk space, it is really not a problem, as each image should not weigh more than 5kB if well compressed.