|
@@ -54,6 +54,12 @@
|
|
|
|
|
|
@property (nonatomic, strong) UIView *headerView;
|
|
|
|
|
|
+@property (nonatomic, assign) BOOL isDrawSignature;
|
|
|
+
|
|
|
+@property (nonatomic, assign) BOOL isTexrSignature;
|
|
|
+
|
|
|
+@property (nonatomic, assign) BOOL isImageSignature;
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation CPDFSignatureEditViewController
|
|
@@ -132,6 +138,7 @@
|
|
|
self.saveButton = [[UIButton alloc] init];
|
|
|
[self.saveButton setTitle:NSLocalizedString(@"Save", nil) forState:UIControlStateNormal];
|
|
|
[self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
|
|
|
+ self.saveButton.enabled = NO;
|
|
|
[self.saveButton addTarget:self action:@selector(buttonItemClicked_Save:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
[self.headerView addSubview:self.saveButton];
|
|
|
|
|
@@ -139,9 +146,11 @@
|
|
|
self.bottomBorder.backgroundColor = [UIColor blackColor].CGColor;
|
|
|
self.textField = [[UITextField alloc] init];
|
|
|
self.textField.delegate = self;
|
|
|
+ self.textField.textColor = [UIColor blackColor];
|
|
|
self.textField.placeholder = NSLocalizedString(@"Enter your signature", nil);
|
|
|
self.textField.textAlignment = NSTextAlignmentCenter;
|
|
|
self.textField.font = [UIFont systemFontOfSize:30];
|
|
|
+ [self.textField addTarget:self action:@selector(textTextField_change:) forControlEvents:UIControlEventEditingChanged];
|
|
|
[self.view addSubview:self.textField];
|
|
|
[self.textField.layer addSublayer:self.bottomBorder];
|
|
|
self.textField.hidden = YES;
|
|
@@ -170,6 +179,10 @@
|
|
|
self.view.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
|
|
|
[self createGestureRecognizer];
|
|
|
[self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
|
|
|
+
|
|
|
+ self.isImageSignature = NO;
|
|
|
+ self.isDrawSignature = NO;
|
|
|
+ self.isImageSignature = NO;
|
|
|
}
|
|
|
|
|
|
- (void)viewWillLayoutSubviews {
|
|
@@ -284,6 +297,75 @@
|
|
|
return textFieldImage;
|
|
|
}
|
|
|
|
|
|
+- (void)initDrawSignatureViewProperties {
|
|
|
+ self.colorSelectView.hidden = NO;
|
|
|
+ self.signatureDrawTextView.hidden = NO;
|
|
|
+ self.selecIndex = CSignatureTopBarDefault;
|
|
|
+ self.colorSelectView.hidden = NO;
|
|
|
+ self.clearButton.hidden = NO;
|
|
|
+ self.signatureDrawTextView.selectIndex = CSignatureDrawText;
|
|
|
+ self.emptyLabel.hidden = NO;
|
|
|
+ self.thicknessView.hidden = NO;
|
|
|
+ self.signatureDrawImageView.hidden = YES;
|
|
|
+ self.createButton.hidden = YES;
|
|
|
+ self.textField.hidden = YES;
|
|
|
+ [self.textField resignFirstResponder];
|
|
|
+
|
|
|
+ if (self.isDrawSignature) {
|
|
|
+ [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
|
|
|
+ self.saveButton.enabled = YES;
|
|
|
+ } else {
|
|
|
+ [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
|
|
|
+ self.saveButton.enabled = NO;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)initTextSignatureViewProperties {
|
|
|
+ self.colorSelectView.hidden = NO;
|
|
|
+ self.signatureDrawTextView.hidden = YES;
|
|
|
+ self.signatureDrawImageView.hidden = YES;
|
|
|
+ self.textField.hidden = NO;
|
|
|
+ self.selecIndex = CSignatureTopBarText;
|
|
|
+ self.colorSelectView.hidden = NO;
|
|
|
+ self.createButton.hidden = YES;
|
|
|
+ self.thicknessView.hidden = YES;
|
|
|
+ self.clearButton.hidden = NO;
|
|
|
+ self.emptyLabel.hidden = YES;
|
|
|
+ [self.textField becomeFirstResponder];
|
|
|
+
|
|
|
+ if (self.isTexrSignature) {
|
|
|
+ [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
|
|
|
+ self.saveButton.enabled = YES;
|
|
|
+ } else {
|
|
|
+ [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
|
|
|
+ self.saveButton.enabled = NO;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)initImageSignatureViewProperties {
|
|
|
+ [self.textField resignFirstResponder];
|
|
|
+ self.colorSelectView.hidden = YES;
|
|
|
+ self.signatureDrawTextView.hidden = YES;
|
|
|
+ self.signatureDrawImageView.hidden = NO;
|
|
|
+ self.textField.hidden = YES;
|
|
|
+ self.selecIndex = CSignatureTopBarImage;
|
|
|
+ self.createButton.hidden = NO;
|
|
|
+ self.colorSelectView.hidden = YES;
|
|
|
+ self.signatureDrawImageView.selectIndex = CSignatureDrawImage;
|
|
|
+ self.thicknessView.hidden = YES;
|
|
|
+ self.clearButton.hidden = YES;
|
|
|
+ self.emptyLabel.hidden = YES;
|
|
|
+ [self.signatureDrawImageView setNeedsDisplay];
|
|
|
+
|
|
|
+ if (self.isImageSignature) {
|
|
|
+ [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
|
|
|
+ self.saveButton.enabled = YES;
|
|
|
+ } else {
|
|
|
+ [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
|
|
|
+ self.saveButton.enabled = NO;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - Action
|
|
|
|
|
|
- (void)buttonItemClicked_Save:(id)sender {
|
|
@@ -326,44 +408,11 @@
|
|
|
|
|
|
- (void)segmentedControlValueChanged_singature:(id)sender {
|
|
|
if (self.segmentedControl.selectedSegmentIndex == 0) {
|
|
|
- self.colorSelectView.hidden = NO;
|
|
|
- self.signatureDrawTextView.hidden = NO;
|
|
|
- self.selecIndex = CSignatureTopBarDefault;
|
|
|
- self.colorSelectView.hidden = NO;
|
|
|
- self.clearButton.hidden = NO;
|
|
|
- self.signatureDrawTextView.selectIndex = CSignatureDrawText;
|
|
|
- self.emptyLabel.hidden = NO;
|
|
|
- self.thicknessView.hidden = NO;
|
|
|
- self.signatureDrawImageView.hidden = YES;
|
|
|
- self.createButton.hidden = YES;
|
|
|
- self.textField.hidden = YES;
|
|
|
- [self.textField resignFirstResponder];
|
|
|
+ [self initDrawSignatureViewProperties];
|
|
|
} else if (self.segmentedControl.selectedSegmentIndex == 1) {
|
|
|
- self.colorSelectView.hidden = NO;
|
|
|
- self.signatureDrawTextView.hidden = YES;
|
|
|
- self.signatureDrawImageView.hidden = YES;
|
|
|
- self.textField.hidden = NO;
|
|
|
- self.selecIndex = CSignatureTopBarText;
|
|
|
- self.colorSelectView.hidden = NO;
|
|
|
- self.createButton.hidden = YES;
|
|
|
- self.thicknessView.hidden = YES;
|
|
|
- self.clearButton.hidden = NO;
|
|
|
- self.emptyLabel.hidden = YES;
|
|
|
- [self.textField becomeFirstResponder];
|
|
|
+ [self initTextSignatureViewProperties];
|
|
|
} else if (self.segmentedControl.selectedSegmentIndex == 2) {
|
|
|
- [self.textField resignFirstResponder];
|
|
|
- self.colorSelectView.hidden = YES;
|
|
|
- self.signatureDrawTextView.hidden = YES;
|
|
|
- self.signatureDrawImageView.hidden = NO;
|
|
|
- self.textField.hidden = YES;
|
|
|
- self.selecIndex = CSignatureTopBarImage;
|
|
|
- self.createButton.hidden = NO;
|
|
|
- self.colorSelectView.hidden = YES;
|
|
|
- self.signatureDrawImageView.selectIndex = CSignatureDrawImage;
|
|
|
- self.thicknessView.hidden = YES;
|
|
|
- self.clearButton.hidden = YES;
|
|
|
- self.emptyLabel.hidden = YES;
|
|
|
- [self.signatureDrawImageView setNeedsDisplay];
|
|
|
+ [self initImageSignatureViewProperties];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -376,12 +425,30 @@
|
|
|
if (self.segmentedControl.selectedSegmentIndex == 0) {
|
|
|
[self.signatureDrawTextView signatureClear];
|
|
|
self.emptyLabel.text = NSLocalizedString(@"Signature Here", nil);
|
|
|
+ self.isDrawSignature = NO;
|
|
|
+ [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
|
|
|
+ self.saveButton.enabled = NO;
|
|
|
} else if (self.segmentedControl.selectedSegmentIndex == 1) {
|
|
|
self.textField.text = @"";
|
|
|
+ self.isTexrSignature = NO;
|
|
|
+ [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
|
|
|
+ self.saveButton.enabled = NO;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+- (void)textTextField_change:(UITextField *)textField {
|
|
|
+ if (self.textField.text.length > 0) {
|
|
|
+ self.isTexrSignature = YES;
|
|
|
+ [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
|
|
|
+ self.saveButton.enabled = YES;
|
|
|
+ } else {
|
|
|
+ self.isTexrSignature = NO;
|
|
|
+ [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
|
|
|
+ self.saveButton.enabled = NO;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - UITextFieldDelegate
|
|
|
|
|
|
- (void)textFieldDidBeginEditing:(UITextField *)textField {
|
|
@@ -395,7 +462,6 @@
|
|
|
self.textField.center = CGPointMake(self.textField.center.x, self.textField.center.y-100);
|
|
|
} completion:nil];
|
|
|
}
|
|
|
- [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
|
|
|
}
|
|
|
|
|
|
- (void)textFieldDidEndEditing:(UITextField *)textField {
|
|
@@ -465,6 +531,12 @@
|
|
|
[picker dismissViewControllerAnimated:YES completion:nil];
|
|
|
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
|
|
|
|
|
|
+ if (image) {
|
|
|
+ self.isImageSignature = YES;
|
|
|
+ [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
|
|
|
+ self.saveButton.enabled = YES;
|
|
|
+ }
|
|
|
+
|
|
|
UIImageOrientation imageOrientation = image.imageOrientation;
|
|
|
if (imageOrientation!=UIImageOrientationUp) {
|
|
|
UIGraphicsBeginImageContext(image.size);
|
|
@@ -536,6 +608,8 @@
|
|
|
|
|
|
- (void)signatureDrawViewStart:(CSignatureDrawView *)signatureDrawView {
|
|
|
[self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
|
|
|
+ self.saveButton.enabled = YES;
|
|
|
+ self.isDrawSignature = YES;
|
|
|
self.emptyLabel.text = @"";
|
|
|
}
|
|
|
|