Let's take a look at the instance effect:
If shown, this is an example in the app, and the client is sent to a friend, and the picture is a tableview.
To implement a small example, if the contents of TableView, there is no more than the current screen display area, we can directly according to the TableView frame, create a picture
Generate picture Uigraphicsbeginimagecontext (shareView.bounds.size) based on view; [Shareview.layer Renderincontext:uigraphicsgetcurrentcontext ()]; UIImage *viewimage = Uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext ();
However, if you encounter too much content, at this time tableview the number of rows will be many, how to intercept the contents of TableView contentsize inside, in fact, to get each cell, a piece of the drawing out on the line. At this point, you need to get the number of rows to the cell and set the RowHeight property of the TableView, which is not much to say. Here's the main code:
Screenshot of TableView-(uiimage*) Screenshotforindexpaths: (nsarray*) indexpaths{cgpoint originaloffset = Self.tableview. Contentoffset;
Uigraphicsbeginimagecontextwithoptions (Cgsizemake (Self.tableView.size.width, self.tableView.rowHeight * [indexp Aths Count]), NO, 0.0); Cgcontextref CTX = Uigraphicsgetcurrentcontext (); ---One to render the cell to Cgcontext uumainvincarmessageviewcell *cell = nil; For (Nsindexpath *indexpath in indexpaths) {//Let the cell be correctly produced on the TableView, then the correct render on the Cgcontext [self.t Ableview Scrolltorowatindexpath:indexpath Atscrollposition:uitableviewscrollpositionnone Animated:NO]; Cell = (uumainvincarmessageviewcell*) [Self.tableview Cellforrowatindexpath:indexpath]; [Cell.layer Renderincontext:ctx]; --The Origin CGCONTEXTTRANSLATECTM (ctx, 0, Self.tableView.rowHeight) to render on the context; --}//---UIImage *image = uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); Self.tableView.contentOffset = Originaloffset; return image;
It's so easy to implement and also record a blog
Http://www.cnblogs.com/kenshincui/p/3959951.html#!comments
ios-intercept TableView Generate pictures