NSString drawInRect: を使用して回転したテキストを描画する方法に関するこの回答を見つけましたが、それがどのように機能するかはわかりません。 =0
私のコードは次のようになります:
CGContextSaveGState(context);
CGContextDrawLinearGradient(context, gradient, CGPointMake(0, centY - halfWidth), CGPointMake(0, centY + halfWidth), 0);
// Add text
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
NSString *str = @"some test string";
CGAffineTransform transform1 = CGAffineTransformMakeRotation(M_PI/4);
CGContextConcatCTM(context, transform1);
CGContextTranslateCTM(context, 0, 0);
UIFont *font = [UIFont systemFontOfSize:16.0];
[str drawInRect:CGRectMake(0, 0, 200, 100) withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UIBaselineAdjustmentNone];
これを使用すると、テキストが x 軸から 45 度下に描画されます。lineargradient に沿ってテキストを垂直に描画したいと考えています。そこで、M_PI/2 を 90 度に使用することでそれができると考えました。しかし、テキストが表示されません。回転のためにさまざまな変換を試しましたが、M_PI/4 や M_PI/8 のように機能するのは一部だけです。-M_PI/4 を使用すると、テキストは x 軸の 45 度上にあり、M_PI/2 は x 軸の 90 度下になると思います。しかし、両方とも何もありません。
何かご意見は?ありがとう。