我正在iphone中构建一个应用程序,我需要绘制一个7位的片段显示,它将显示用户输入的数字。我使用的是CGPath和CGcontext。我画了7位段作为数字clock.But中的no,我没有办法显示用户给出的no。要绘制7位段显示,我已经完成了..
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); 任何帮助都将不胜感激。
发布于 2011-07-26 15:41:24
你真的需要画它吗?我确定10张图片,每个数字一张,会更令人满意。
从注释编辑:
如果您将图像命名为0.png 1.png 2.png等,则可以使用用户输入的整数值快速更改显示的图像。如果你担心浪费磁盘空间,这真的不是问题,因为如果压缩良好,每个图像的重量不应该超过5kB。
发布于 2015-11-11 14:57:41
更有效的方法是,为什么不直接使用带有digital font的标签。这将为您节省大量工作,并为您提供大量的灵活性和可控性。下面是一个简单的例子
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);https://stackoverflow.com/questions/6826720
复制相似问题