简单而有效的方法:
1、为UIView建立Category
#import <UIKit/UIKit.h>
@interface UIView (saveImageWithScale)
- (UIImage *)saveImageWithScale:(float)scale;
@end
#import "UIView+saveImageWithScale.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIView (saveImageWithScale)
- (UIImage *)saveImageWithScale:(float)scale
{
UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, scale);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end
现在即可将任意的UIView保存为Image并且是真实尺寸。
亲测,有效