PDFLinkViewController.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // PDFLinkViewController.m
  3. // PDFReader
  4. //
  5. // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // The PDF Reader Sample applications are licensed with a modified BSD license.
  8. // Please see License for details. This notice may not be removed from this file.
  9. //
  10. #import "PDFLinkViewController.h"
  11. @interface PDFLinkViewController ()
  12. @property (nonatomic,assign) IBOutlet UIView *contentView;
  13. @property (nonatomic,assign) IBOutlet UIButton *websiteButton;
  14. @property (nonatomic,assign) IBOutlet UIButton *pageButton;
  15. @property (nonatomic,assign) IBOutlet UIButton *emailButton;
  16. @property (nonatomic,assign) IBOutlet UILabel *websiteLabel;
  17. @property (nonatomic,assign) IBOutlet UILabel *pageLabel;
  18. @property (nonatomic,assign) IBOutlet UILabel *emailLabel;
  19. @property (nonatomic,assign) IBOutlet UITextField *textField;
  20. @end
  21. @implementation PDFLinkViewController
  22. #pragma mark - Init Methods
  23. - (void)dealloc {
  24. Block_release(_callback);
  25. [_content release];
  26. [super dealloc];
  27. }
  28. #pragma mark - UIViewController Methods
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. // Do any additional setup after loading the view from its nib.
  32. self.contentView.layer.cornerRadius = 6.0;
  33. self.contentView.backgroundColor = [UIColor colorWithWhite:247.0/255.0 alpha:1.0];
  34. [self.textField setReturnKeyType:UIReturnKeyDone];
  35. self.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
  36. self.textField.text = self.content;
  37. [self updataSubview];
  38. }
  39. - (void)viewWillAppear:(BOOL)animated {
  40. [super viewWillAppear:animated];
  41. [self.textField becomeFirstResponder];
  42. }
  43. - (void)viewWillDisappear:(BOOL)animated {
  44. [super viewWillDisappear:animated];
  45. [self.textField resignFirstResponder];
  46. }
  47. - (void)updataSubview {
  48. self.websiteButton.selected =
  49. self.pageButton.selected =
  50. self.emailButton.selected = NO;
  51. self.websiteLabel.textColor =
  52. self.pageLabel.textColor =
  53. self.emailLabel.textColor = [UIColor colorWithRed:118.0/255 green:118.0/255 blue:118.0/255 alpha:1.0];
  54. if (self.type == 0) {
  55. // Website
  56. self.websiteButton.selected = YES;
  57. self.websiteLabel.textColor = [UIColor colorWithRed:9.0/255 green:147.0/255 blue:225.0/255 alpha:1.0];
  58. [self.textField setKeyboardType:UIKeyboardTypeURL];
  59. self.textField.placeholder = [NSString stringWithFormat:@"https://www.google.com"];
  60. } else if (self.type == 1) {
  61. // Page Number
  62. self.pageButton.selected = YES;
  63. self.pageLabel.textColor = [UIColor colorWithRed:9.0/255 green:147.0/255 blue:225.0/255 alpha:1.0];
  64. [self.textField setKeyboardType:UIKeyboardTypeNumberPad];
  65. self.textField.placeholder = @"";
  66. } else {
  67. // Email
  68. self.emailButton.selected = YES;
  69. self.emailLabel.textColor = [UIColor colorWithRed:9.0/255 green:147.0/255 blue:225.0/255 alpha:1.0];
  70. [self.textField setKeyboardType:UIKeyboardTypeEmailAddress];
  71. self.textField.placeholder = @"example@email.com";
  72. }
  73. }
  74. #pragma mark - Button Actions
  75. - (IBAction)buttonItemClicked_Switch:(id)sender {
  76. self.type = [sender tag];
  77. [self updataSubview];
  78. }
  79. - (IBAction)buttonItemClicked_Cancel:(id)sender {
  80. [self dismissViewControllerAnimated:YES completion:^{
  81. if (self.callback) {
  82. self.callback(nil, self.type);
  83. self.callback = nil;
  84. }
  85. }];
  86. }
  87. - (IBAction)buttonItemClicked_Done:(id)sender {
  88. [self dismissViewControllerAnimated:YES completion:^{
  89. NSString *text = self.textField.text.length > 0 ? self.textField.text: nil;
  90. self.content = text;
  91. if (self.callback) {
  92. self.callback(text, self.type);
  93. self.callback = nil;
  94. }
  95. }];
  96. }
  97. @end