Display digit in digital form(digital clock)
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.png
1.png
2.png
etc., 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.
even more efficient, why don't you just use a label with a digital font. This will save you a lot of work and will give you a lot of flexibility and control. below is a simple example
timerDisplay = Label::createWithTTF("00:00:00", "fonts/digital-7.ttf", 32);
timerDisplay->setPosition(Point((visibleSize.width -
timerDisplay->getContentSize().width)/2, visibleSize.height));
timerDisplay->setAlignment(TextHAlignment::CENTER);
this->addChild(timerDisplay);
精彩评论