Render whole UITableView as an UIImage fails on iOS 7

I have a very long UITableView, and I want to export it as an UIImage. Following is my code:

- (UIImage*)imageFromTableView { UITableView *view = self.tableView; CGSize size = view.bounds.size; size.height = [self maxYOfRestaurantCellInTableView]; CGPoint oldOffset = view.contentOffset; CGRect oldFrame = view.frame; UIGraphicsBeginImageContextWithOptions(size, YES, [[UIScreen mainScreen] scale]); view.contentOffset = CGPointMake(0, 0); view.frame = CGRectMake(0, 0, size.width, size.height); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); view.contentOffset = oldOffset; view.frame = oldFrame; return image; }

The trick is: temporarily set the frame of the tableview to its content size, hoping it will force the tableview to load all cells.

The above code works fine on iOS8. However, on iOS7, only areas ON the screen are rendered, and areas outside the screen are black in the exported image.

Could anyone help?

Category:ios Time:2018-11-23 Views:1
Tags: ios

Related post

  • Store whole UITableView in PDF File 2011-12-14

    I'm using code to create a PDF File. Works. But: I want my whole UITableView(I need to scroll) in my PDF File and not just the part of the view which is currently displayed on screen. Is there a way to achieve this? Thanks a lot. CODE: NSString * new

  • How can i create an UITableView on Xcode 4.2,for IOS 5? 2011-10-26

    Last week i have downloaded Xcode 4.2, so when i started building apps i've tried to add an UITableView to one of my projects (as normal as i have been doing since i began developing) but the UITableView isn't working. I've searching for tutorials bu

  • NSXMLParser failed in iOS 6 with NSXMLParserErrorDomain=68 2014-04-09

    I am facing parsing failed issue in iOS 6 and above only. The code is working in previous version of iOS 6, but not woking in iOS 6 and above. I am trying to send login request to server url. I am getting the response from server in xml format. I am

  • Creating CGImageContext for resizing UIImage fails in simulator 2009-01-24

    I've got some code to resize a UIImage (in a category to UIImage), that first generates an Image Context: CGImageRef oldImage = [self CGImage]; CGSize oldSize = [self size]; CGContextRef context = CGBitmapContextCreate(NULL, //Data newSize.width, //W

  • Backed-up Whole Registry (Regedit.exe) - Restoring Fails - System Restore points not showing. 2012-05-22

    - Tried to backup Vista Home Premium to XP Home over Network - Followed instructions online to change Registry keys for "LmCompatibilityLevel" - Before changing entries, Backed-up individual registry on Desktop and "whole registry" in My Documents (b

  • Render partial in an extension method fails 2010-07-06

    I'm creating a tabcontainer that shows information from partials. The code that i've created is as follows: //Entering extension method, m_helper is of type HtmlHelper foreach (var tab in m_tabList) { sb.AppendLine("<div class='tabContent'>");

  • When editing UITableView, clicking red dot fails to display 'Delete' button 2011-03-18

    A table view is contained in a regular view. As expected, taping 'Edit' button (in that table view) displays 'red dot with minus sign' for each row (that is, method 'setEditing' executes OK). However, clicking such red dot does NOT display the corres

  • How to not render whole block in JSF? 2011-12-06

    Is there a JSF 2.1 component which lets me conditionally render (or not render) all its content? Something like <h:component rendered="#{user.loggedIn}"> ...a bunch of jsf components and HTML code... ...even more HTML code... </h:component

  • CoreData lightweight migration failing on iOS 2011-06-19

    I'm trying to migrate my core data data to a new version. The only change I've done is adding one field (NSString *sessionId) So what I've done: 1. Create version 2 of my core data file 2. Add sessionId in this file. 3. set version 2 as default. 4. a

  • Deleting from UITableView and supporting data source in iOS 4 2011-06-23

    I'm a bit stumped by this after reading over the Apple documentation and searching The Googles. The gist of the problem is I know I need to delete from the UITableView and the datasource (NSMutableArray in this case) but it won't let me do either reg

  • Reloading UITableView based on settings in an iOS app 2011-07-24

    I'm trying to get a UITableView to be dependent upon an in app setting. Based on the value of the setting, the UITableView (in the RootViewController) would display the appropriate number of cells in the table. I check the setting (which is set by an

  • how do I render an NSObject in local HTML template in iOS 2011-08-15

    I have a local html file I would like to use as a template to print some different NSObjects, is there a way to render this without having to do a bunch of stringByReplacingOccuranceOfString methods? Looking for something I would do in MVC on a web s

  • How to render 3D shape with transparency using GLKit in iOS 2011-12-06

    I have some 3D shape defined by set of Vertices/normal/indices. I wish to render some object with semi-transperency. Some objects have textures and some do not. I am using GLKit for the development on iOS. Kindly tell how can I achieve the effect? --

  • PHP is_uploaded_file fails for iOS app 2011-12-14

    I'm writing the PHP/webserver side of an image upload for an iOS app. Using an html file I can upload an image to my script just fine. I've even written a Perl LWP script to post an image with no problems. When the iOS app uploads an image it fails w

  • Change background on a UITableView embedded in a UIViewController on iOS 5 2012-01-22

    I am trying to change the grey gradient background on an embedded UITableView to the color I have set on the parent view in the Storyboard. I have been looking around, and found the following threads: Change iPhone tableview (style grouped) backgroun

  • Compiling Speex successful on iPhone simulator but failed on iOS device 2012-02-24

    I tried to compile Speex library on iOS following this tutorial and succeeded to do it in the iPhone simulator, but the build fails on a real device. I get some errors like "Use of undeclared identifier __m128", which looks like there are some proble

  • UIImage and NSCoding iOS 5.1 2012-03-08

    Prior to iOS 5.1 if you wanted to use NSCoding protocols with UIImage you had to do something like this. @interface UIImage (NSCoding) -(id)initWithCoder:(NSCoder *)deocder; -(void)encodeWithCoder:(NSCoder *)encoder; @end Then implement it yourself.

  • How to set editing button on UITableView that is a subview on iOS 2012-03-15

    I have a UIViewController which has a UITableView as a child besides other elements. I want to add editing support on that tableView with this simple line: self.navigationItem.rightBarButtonItem = self.editButtonItem; It works if I set this on UITabl

  • GCD network requests failing on iOS 4 2012-03-22

    I have the following code in my application to load some data from my API. It works fine, great in fact in iOS 5 but on iOS 4 I am getting so many responses with status 204. This only happens on iOS 4, this could have been treated as an API error, bu

Copyright (C), All Rights Reserved.

processed in 0.743 (s). 13 q(s)