// // CPDFWatermarkViewController.m // PDFViewer // // Created by kdanmobile_2 on 2023/1/12. // #import "PDFWatermarkViewController.h" #import "PDFWatermarkControllerHeader.h" @interface PDFWatermarkViewController () @end @implementation PDFWatermarkViewController #pragma mark - UIViewController Methods - (void)viewDidLoad { [super viewDidLoad]; _dataModel = [[PDFWatermarkDataModel alloc] init]; [self initDataModel]; } - (void)initDataModel { } - (void)onSelectPageRange:(UIButton *)sender { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *defaultRange = [UIAlertAction actionWithTitle:NSLocalizedString(@"All Pages", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; UIAlertAction *customRange = [UIAlertAction actionWithTitle:NSLocalizedString(@"Custom Page Range", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self createCustomRangeAlert]; }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alertController addAction:defaultRange]; [alertController addAction:customRange]; [alertController addAction:cancelAction]; [self presentViewController:alertController animated:YES completion:nil]; } - (void)createCustomRangeAlert { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Custom Page Range", nil) message:nil preferredStyle:UIAlertControllerStyleAlert]; [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.placeholder = NSLocalizedString(@"such as:1,3-5,10", nil); }]; [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Done", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { self.dataModel.pageString = alertController.textFields.firstObject.text; }]]; [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]]; [self presentViewController:alertController animated:YES completion:nil]; } - (BOOL)validateValue:(NSString *)number { BOOL res = YES; NSCharacterSet *numberSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"]; NSInteger i = 0; while (i < number.length) { NSString *str = [number substringWithRange:NSMakeRange(i, 1)]; NSRange range = [str rangeOfCharacterFromSet:numberSet]; if (range.length == 0) { res = NO; break; } i++; } return res; } @end