【问题标题】:Display digit in digital form(digital clock)以数字形式显示数字(数字时钟)
【发布时间】:2011-07-26 07:33:16
【问题描述】:

我正在 iphone 中构建一个应用程序,我需要绘制一个 7 位段显示,它将显示用户输入的数字。我正在使用 CGPath 和 CGcontext。 我已经绘制了 7 位段作为数字时钟中的否。但是,我没有办法显示用户给定的否。要绘制一个 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); 

任何帮助将不胜感激。

【问题讨论】:

标签: iphone objective-c cocos2d-iphone


【解决方案1】:

你真的需要画吗?我敢肯定,10 张图片,每个数字一张,会更令人满意。

从评论中编辑:
如果您将图像命名为0.png1.png2.png 等,您可以使用用户输入的整数值快速更改显示的图像。如果您担心浪费磁盘空间,这真的不是问题,因为如果压缩得好,每个图像的重量不应超过 5kB。

【讨论】:

  • 不,我需要为数字 0 绘制一条路径,然后根据数字输入我需要更改该路径。我不需要 10 张图片。
  • 我认为您可以通过图像获得更好的设计,如果您将图像命名为 0.png 1.png 2.png 等,您可以使用整数值非常快速地切换显示的图像.如果您担心浪费磁盘空间,这真的不是问题,因为如果压缩得好,每个图像的重量不应超过 5kB。但这取决于你;)
  • thnx Buddy,我现在将切换到你的答案。
【解决方案2】:

更高效,为什么不直接使用带有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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-16
    • 1970-01-01
    • 2016-01-10
    • 2011-06-15
    • 1970-01-01
    相关资源
    最近更新 更多