我正在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);
任何幫助將不勝感激。
你也可以使用自定義字體:http://www.dafont.com/ds-digital.font – rckoenes
但是我沒有使用自定義字體。 – iCoder4777