// // PDFLinkViewController.m // PDFReader // // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved. // // The PDF Reader Sample applications are licensed with a modified BSD license. // Please see License for details. This notice may not be removed from this file. // #import "PDFLinkViewController.h" @interface PDFLinkViewController () @property (nonatomic,assign) IBOutlet UIView *contentView; @property (nonatomic,assign) IBOutlet UIButton *websiteButton; @property (nonatomic,assign) IBOutlet UIButton *pageButton; @property (nonatomic,assign) IBOutlet UIButton *emailButton; @property (nonatomic,assign) IBOutlet UILabel *websiteLabel; @property (nonatomic,assign) IBOutlet UILabel *pageLabel; @property (nonatomic,assign) IBOutlet UILabel *emailLabel; @property (nonatomic,assign) IBOutlet UITextField *textField; @end @implementation PDFLinkViewController #pragma mark - Init Methods - (void)dealloc { Block_release(_callback); [_content release]; [super dealloc]; } #pragma mark - UIViewController Methods - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. self.contentView.layer.cornerRadius = 6.0; self.contentView.backgroundColor = [UIColor colorWithWhite:247.0/255.0 alpha:1.0]; [self.textField setReturnKeyType:UIReturnKeyDone]; self.textField.clearButtonMode = UITextFieldViewModeWhileEditing; self.textField.text = self.content; [self updataSubview]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.textField becomeFirstResponder]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.textField resignFirstResponder]; } - (void)updataSubview { self.websiteButton.selected = self.pageButton.selected = self.emailButton.selected = NO; self.websiteLabel.textColor = self.pageLabel.textColor = self.emailLabel.textColor = [UIColor colorWithRed:118.0/255 green:118.0/255 blue:118.0/255 alpha:1.0]; if (self.type == 0) { // Website self.websiteButton.selected = YES; self.websiteLabel.textColor = [UIColor colorWithRed:9.0/255 green:147.0/255 blue:225.0/255 alpha:1.0]; [self.textField setKeyboardType:UIKeyboardTypeURL]; self.textField.placeholder = [NSString stringWithFormat:@"https://www.google.com"]; } else if (self.type == 1) { // Page Number self.pageButton.selected = YES; self.pageLabel.textColor = [UIColor colorWithRed:9.0/255 green:147.0/255 blue:225.0/255 alpha:1.0]; [self.textField setKeyboardType:UIKeyboardTypeNumberPad]; self.textField.placeholder = @""; } else { // Email self.emailButton.selected = YES; self.emailLabel.textColor = [UIColor colorWithRed:9.0/255 green:147.0/255 blue:225.0/255 alpha:1.0]; [self.textField setKeyboardType:UIKeyboardTypeEmailAddress]; self.textField.placeholder = @"example@email.com"; } } #pragma mark - Button Actions - (IBAction)buttonItemClicked_Switch:(id)sender { self.type = [sender tag]; [self updataSubview]; } - (IBAction)buttonItemClicked_Cancel:(id)sender { [self dismissViewControllerAnimated:YES completion:^{ if (self.callback) { self.callback(nil, self.type); self.callback = nil; } }]; } - (IBAction)buttonItemClicked_Done:(id)sender { [self dismissViewControllerAnimated:YES completion:^{ NSString *text = self.textField.text.length > 0 ? self.textField.text: nil; self.content = text; if (self.callback) { self.callback(text, self.type); self.callback = nil; } }]; } @end