我想在视图中绘制一些文字,旋转90°。我对iPhone开发很陌生,并且在网络上发现了许多不同的解决方案。我已经尝试了一些,通常最终我的文字被剪辑。iPhone:绘制旋转文字?
这是怎么回事? I am绘制在一个相当小的空间(一个表格视图单元格),但必须有一个“正确”的方式来做到这一点...对吗?
编辑:下面是几个例子。我试图在左边的黑色条上显示文字“”。
第一次尝试,从RJShearman on the Apple Discussions
CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSelectFont (context, "Helvetica-Bold", 16.0, kCGEncodingMacRoman); CGContextSetTextDrawingMode (context, kCGTextFill); CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0); CGContextSetTextMatrix (context, CGAffineTransformRotate(CGAffineTransformScale(CGAffineTransformIdentity, 1.f, -1.f), M_PI/2)); CGContextShowTextAtPoint (context, 21.0, 55.0, [_cell.number cStringUsingEncoding:NSUTF8StringEncoding], [_cell.number length]); CGContextRestoreGState(context);
第二次尝试,从zgombosi on iPhone Dev SDK。相同的结果(字体在这里略小,所以裁剪更少)。
CGContextRef context = UIGraphicsGetCurrentContext(); CGPoint point = CGPointMake(6.0, 50.0); CGContextSaveGState(context); CGContextTranslateCTM(context, point.x, point.y); CGAffineTransform textTransform = CGAffineTransformMakeRotation(-1.57); CGContextConcatCTM(context, textTransform); CGContextTranslateCTM(context, -point.x, -point.y); [[UIColor redColor] set]; [_cell.number drawAtPoint:point withFont:[UIFont fontWithName:@"Helvetica-Bold" size:14.0]]; CGContextRestoreGState(context);
确实有几种方法可以解决这个问题。提供一些关于你已经尝试了什么以及如何解决问题的细节(它是如何被删减的?)会让它更容易有效地回答。 – 2009-11-09 21:17:39
提供了详细信息。 – s4y 2009-11-09 23:15:49