iOS_屏幕截图

github地址: https://github.com/mancongiOS/UIImage.git

UIImage的category

UIView+ImageScreenShot.h

#import <UIKit/UIKit.h>

@interface UIView (ImageScreenShot)

- (UIImage *)imageScreenShot;

@end

UIView+ImageScreenShot.m

#import "UIView+ImageScreenShot.h"

@implementation UIView (ImageScreenShot)

- (UIImage *)imageScreenShot {

    UIGraphicsBeginImageContext(self.frame.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); return image;
} @end

使用:

    self.view.backgroundColor = [UIColor redColor];

    UIImage * image = [self.view imageScreenShot];

    if (image) {
self.view.backgroundColor = [UIColor whiteColor]; self.imageView.image = image;
}
上一篇:UIView的无损截图


下一篇:[SecureCRT] 解决 securecrt failed to open the host key database file 的问题