#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize drawSignView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)actionSave:(id)sender
{
// code for save the signature
UIGraphicsBeginImageContext(self.drawSignView.bounds.size);
[[self.drawSignView.layer presentationLayer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *postData = UIImageJPEGRepresentation(viewImage, 1.0);
....Then do your stuff to save this in DB or server
}
- (IBAction)actionCancel:(id)sender
{
//code for cancel the signature
[self.drawSignView erase];
}
- (IBAction)actionClear:(id)sender
{
//code for clear the signature
[self.drawSignView erase];
}
@end
NOTE:When you set the view in xib first identity inspector(it is left> side in utilities).Then click the drop down box of class(it is part of
Custom Class).Select or choose SignatureDrawView.After that hook up
the view from xib or storyboard to ViewController.h
You can draw signature on
UIView
for that firstsubclass UIView
and your subclass ofUIView
should be something like,SignatureView.h
SignatureView.m
Then you can
import SignatureView.h
in any your view controller and can instantiate signature view something like,And on that view you can draw your signature!
And you can call
erase
method toerase
the signature!This my solution.
First I created the SignatureDrawView class.In side the SignatureDrawView class I wrote the function for the draw the signature.
SignatureDrawView.h
SignatureDrawView.m
Next in ViewController I created the UIImageView with UIView.
ViewController.h
ViewController.m
Below is the output screenshots
Also