我想在視圖中繪製一些文字,旋轉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