Take a local screenshot of the cell in iOS

Source: Internet
Author: User

today, in the development process, a problem is encountered, that is, a control needs to be done separately. If you are on the screen, I believe you are familiar with it, but for a single control? For example, the most common UITableViewCell, because the cell is one of the most commonly used controls, if you know it, then other controls will be solved.


This apple seems to have helped us to think about it, if you support the iOS7 and above the system, then only need to call a line of code.


UIView *snapshot = [Thecell snapshotviewafterscreenupdates:yes];

Isn't it convenient?


But let's look at the definition of this method:

-(UIView *) Snapshotviewafterscreenupdates: (BOOL) afterupdates Ns_available_ios (7_0);

I wipe! Only support iOS7 and above! Can that iOS6 be swollen? Will not run a crash?


Table anxious ~IOS6 on our own way ~


        CGRect rect = [self RectForRowAtIndexPath:self.indexOfTheCell];        Uigraphicsbeginimagecontext (rect.size);        Cgcontextref context = Uigraphicsgetcurrentcontext ();        [Thecell.layer Renderincontext:context];        UIImage *img = Uigraphicsgetimagefromcurrentimagecontext ();        Uigraphicsendimagecontext ();                Uiimageview *imageview = [[Uiimageview alloc] initwithframe:rect];        Imageview.image = img;

hahaha. We got it!


So we just need to set up a branch and then we can.


The cell is localized in iOS

Related Article

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.