PDFWatermarkViewController.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // CPDFWatermarkViewController.m
  3. // PDFViewer
  4. //
  5. // Created by kdanmobile_2 on 2023/1/12.
  6. //
  7. #import "PDFWatermarkViewController.h"
  8. #import "PDFWatermarkControllerHeader.h"
  9. @interface PDFWatermarkViewController ()
  10. @end
  11. @implementation PDFWatermarkViewController
  12. #pragma mark - UIViewController Methods
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. _dataModel = [[PDFWatermarkDataModel alloc] init];
  16. [self initDataModel];
  17. }
  18. - (void)initDataModel {
  19. }
  20. - (void)onSelectPageRange:(UIButton *)sender {
  21. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  22. UIAlertAction *defaultRange = [UIAlertAction actionWithTitle:NSLocalizedString(@"All Pages", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  23. }];
  24. UIAlertAction *customRange = [UIAlertAction actionWithTitle:NSLocalizedString(@"Custom Page Range", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  25. [self createCustomRangeAlert];
  26. }];
  27. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  28. }];
  29. [alertController addAction:defaultRange];
  30. [alertController addAction:customRange];
  31. [alertController addAction:cancelAction];
  32. [self presentViewController:alertController animated:YES completion:nil];
  33. }
  34. - (void)createCustomRangeAlert {
  35. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Custom Page Range", nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  36. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  37. textField.placeholder = NSLocalizedString(@"such as:1,3-5,10", nil);
  38. }];
  39. [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Done", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  40. self.dataModel.pageString = alertController.textFields.firstObject.text;
  41. }]];
  42. [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  43. }]];
  44. [self presentViewController:alertController animated:YES completion:nil];
  45. }
  46. - (BOOL)validateValue:(NSString *)number {
  47. BOOL res = YES;
  48. NSCharacterSet *numberSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
  49. NSInteger i = 0;
  50. while (i < number.length) {
  51. NSString *str = [number substringWithRange:NSMakeRange(i, 1)];
  52. NSRange range = [str rangeOfCharacterFromSet:numberSet];
  53. if (range.length == 0) {
  54. res = NO;
  55. break;
  56. }
  57. i++;
  58. }
  59. return res;
  60. }
  61. @end