NSString の元の "drawInRect" を置き換える "myDrawInRect" インターフェイスを作成しました。
コードは次のようになります。
.h ファイル:
@interface NSString(TextDrawing)
-(CGSize) myDrawInRect:(CGRect)rect withFont:(UIFont *)font textColor:(UIColor*)textColor
lineBreakMode:(NSLineBreakMode)lineBreakMode alignment:(NSTextAlignment)alignment;
@end
.m ファイル:
@interface NSString(TextDrawing)
-(CGSize) myDrawInRect:(CGRect)rect withFont:(UIFont *)font textColor:(UIColor*)textColor
lineBreakMode:(NSLineBreakMode)lineBreakMode alignment:(NSTextAlignment)alignment
{
CGFloat screen_scale = [UIScreen mainScreen].scale;
CGContextRef bitmapContext = CreateBitmapContext( rect.size.width * screen_scale, rect.size.height * screen_scale );
/* ... some code to draw the bitmapContext; */
CGImageRef image = CGBitmapContextCreateImage( bitmapContext );
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextScaleCTM( context, 1.0f, -1.0f );
CGContextTranslateCTM( context, 0.0f, -CGRectGetHeight(realRect) );
CGContextDrawImage( context, rect, image );
CGContextRelease( bitmapContext );
CGImageRelease( myImage );
}
@end
UILabel drawInRect で myDrawInRect を呼び出しましたが、ラベルには何も表示されません。誰でもアドバイスできますか?ありがとう!