Question

I am using this signature class to add signatures to my iOS application: https://github.com/jharwig/SignatureDemo/blob/master/SignatureDemo/NICSignatureView.h

I have the signature view in a storyboard form sheet, and I am able to draw and everything and it works....

However, I want to save the signature as an image. To do that, I am doing this:

UIView *view = self.view;
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);

The image, however, is all white, without the signature. I assume that is becuase the view is not add programmatically, but with a storyboard. However, the addSubview is not adding the view.

The signature class also has a built in method to return a UIImage, but I am unsure how to call this from a view controller that has the view set in a storyboard.

So my question is, how can I get the image?

Was it helpful?

Solution

Add this property to your view controller

@property (retain, nonatomic) IBOutlet UIView* mySigView;

Connect mySigView property with your UIView (NICSignatureView) in storyboard

Trigger the following action in your view controller after you hit a save button:

NICSignatureView* sig = (NICSignatureView *)self.mySigView;
UIImage* myimage = [sig signatureImage];
UIImageWriteToSavedPhotosAlbum(myimage, nil, nil, nil);

Do not forget to import NICSignatureView.h in your view controller

#import "NICSignatureView.h"

You can now find the signature in your camera roll

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top