2017-01-30 13 views
0

でUILabelをレンダリング:centerLabel.transform = CGAffineTransformMakeRotation((90 * M_PI)/180);私はUILabel(変換とUILabel)を回転させている変換

私はUIImageに私UILabelをレンダリングする必要がありますが、私はそれを変換して作成することはできません。私はUILabelをレンダリングするときに変換なしでUILabelを取得しています。どうしたらいいですか?

これは私の方法である:

+ (UIImage *) imageWithView:(UIView *)view andOpaque:(BOOL)opaque { 
UIGraphicsBeginImageContextWithOptions(view.bounds.size, opaque, 0.0); 
[view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
return img; 
} 

答えて

0

このコードを試してみてください、UILabelからイメージを作成するには:

#import <QuartzCore/QuartzCore.h> 
#import <QuartzCore/CALayer.h> 

はあなたUILabelその後

centerLabel.transform = CGAffineTransformMakeRotation((90 * M_PI)/180); 

を回転させますキャプチャを保存するUIImage

UIImage *image = [self imageWithView:centerLabel]; 

撮像画像におけるD画像は回転せずになります。そのイメージをローテーションで使用する場合は、CGAffineTransformMakeRotationUIImageViewに、UILabelをキャプチャした後に使用する必要があります。

- (UIImage *) imageWithView:(UIView *)view 
{ 
    // Create a "canvas" (image context) to draw in. 
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, 0.0); // high res 

    // Make the CALayer to draw in our "canvas". 
    [[view layer] renderInContext: UIGraphicsGetCurrentContext()]; 

    // Fetch an UIImage of our "canvas". 
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 

    // Stop the "canvas" from accepting any input. 
    UIGraphicsEndImageContext(); 

    // Return the image. 
    return image; 
} 
関連する問題