ios-intercept TableView Generate pictures

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.