So, I am taking a screenshot of a subclass of UIView, which I save in the photo stream of the device.
Problem:
The problem is that I am using resizableImageWithCapInsets to add a stretched background to my UIView, but that background is clipped on the right side and I have no idea why. If someone can help me, it will be very grateful.

I add a stretched background to my UIView as follows:
[diagramBase addSubview:[self addTileBackgroundOfSize:diagramBase.frame andType:@"ipad_diagram_border.png"]];
Which call calls this method:
- (UIImageView *) addTileBackgroundOfSize:(CGRect)frame andType:(NSString *)type { frame.origin.x = 0.0f; frame.origin.y = 0.0f; UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:frame]; UIImage *image = [UIImage imageNamed:type]; UIEdgeInsets insets = UIEdgeInsetsMake(10.0f, 10.0f, 10.0f, 10.0f); UIImage *backgroundImage = [image resizableImageWithCapInsets:insets]; backgroundView.image = backgroundImage; return backgroundView; }
The actual print screen is done using this method (RINDiagramView is the name of my subclass of UIView where I take the screenshot). The rotation happens there, because I need the image to rotate when I save it, but I commented on this part, and itβs not that the background is acting strange.
- (UIImage *) createSnapshotOfView:(RINDiagram *) view { CGRect rect = [view bounds]; rect.size.height = rect.size.height - 81.0f; UIGraphicsBeginImageContextWithOptions(rect.size, YES, 0.0f); CGContextRef context = UIGraphicsGetCurrentContext(); [view.layer renderInContext:context]; UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImage *finalImage = [[UIImage alloc] initWithCGImage: capturedScreen.CGImage scale: 1.0 orientation: UIImageOrientationLeft]; return finalImage; }
I am using Xcode 5.1 and everything is done programmatically (without storyboard, etc.). The base SDK is iOS 7.1.
source share