#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller-(void) viewdidload { [ Super Viewdidload]; Additional setup after loading the view, typically from a nib. Turn on bitmap context uigraphicsbeginimagecontextwithoptions (self.view.bounds.size, NO, 0); Gets the context cgcontextref CTX = Uigraphicsgetcurrentcontext (); Render the layer on the control to the context (the layer can only render cannot be drawn) [Self.view.layer renderincontext:ctx]; Production of a picture UIImage *image = Uigraphicsgetimagefromcurrentimagecontext (); Close context uigraphicsendimagecontext (); Convert the image into binary png nsdata *imagedata = uiimagepngrepresentation (image); Write to Desktop [imageData writetofile:@ "/users/zhaotian/desktop/view.png" Atomically:yes]; } -(void) didreceivememorywarning { [super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
Screenshot of iOS screen