// // HeaderFooterAlertViewController.m // PDFViewer // // Created by kdanmobile_2 on 2022/11/16. // #import "PDFHeaderFooterAddController.h" #import "PDFAddViewControllerHeader.h" @interface PDFHeaderFooterAddController () @property (nonatomic,strong) NSMutableArray *dataArray; @property (retain, nonatomic) IBOutlet UILabel *localLabel; @property (retain, nonatomic) IBOutlet UISegmentedControl *localSegment; @property (retain, nonatomic) IBOutlet UILabel *alignmentLabel; @property (retain, nonatomic) IBOutlet UISegmentedControl *aligbmentSegment; @property (retain, nonatomic) IBOutlet UILabel *colorLabel; @property (retain, nonatomic) IBOutlet UIImageView *colerImage; @property (retain, nonatomic) IBOutlet UISlider *colorSlider; @property (retain, nonatomic) IBOutlet UILabel *pageNumberLabel; @property (retain, nonatomic) IBOutlet UITextField *pageNumberText; @property (retain, nonatomic) IBOutlet UILabel *fontSizeLabel; @property (retain, nonatomic) IBOutlet UITextField *fontSizeText; @property (retain, nonatomic) IBOutlet UILabel *pageIndexLabel; @property (retain, nonatomic) IBOutlet UITextField *pageIndexNumberText; @property (retain, nonatomic) IBOutlet UIImageView *preImaview; @property (retain, nonatomic) IBOutlet UILabel *preLabel1; @property (retain, nonatomic) IBOutlet UILabel *preLabel2; @property (retain, nonatomic) IBOutlet UILabel *preLabel3; @property (retain, nonatomic) IBOutlet UILabel *preLabel4; @property (retain, nonatomic) IBOutlet UILabel *preLabel5; @property (retain, nonatomic) IBOutlet UILabel *preLabel; @property (retain, nonatomic) IBOutlet UIView *pageFormatView; @property (retain, nonatomic) IBOutlet UILabel *titleView; @property (retain, nonatomic) IBOutlet UIButton *okBtn; @property (retain, nonatomic) IBOutlet UITableView *tableView; @property (retain, nonatomic) IBOutlet UIView *headerFooterView; @end @implementation PDFHeaderFooterAddController #pragma mark - UIViewController Methods - (void)viewDidLoad { [super viewDidLoad]; // UI event [self initHeadView]; [self initButtonView]; } - (void)viewDidLayoutSubviews { [self initBasicEvent]; [self initExtendEvent]; } #pragma mark - Initializers - (void)initModel { self.modelData = [[PDFHeaderFooterModel alloc] init]; self.modelData.fontSize = 18.0; self.modelData.fontSelcet = 0; self.modelData.fontPosition = 0; self.modelData.pageStart = @"1"; } - (void)initHeadView { _preImaview.image = self.image; CALayer *layer = [_preImaview layer]; layer.borderColor = [[UIColor blackColor] CGColor]; layer.borderWidth = 0.2f; _preLabel1.hidden = NO; _preLabel2.hidden = YES; _preLabel3.hidden = YES; _preLabel4.hidden = YES; _preLabel5.hidden = YES; _preLabel.hidden = YES; } - (void)initButtonView { _fontSizeText.delegate = self; _pageIndexNumberText.delegate = self; } - (void)initBasicEvent { [_localSegment addTarget:self action:@selector(changeLocation:) forControlEvents:UIControlEventValueChanged]; [_aligbmentSegment addTarget:self action:@selector(changeAligbment:) forControlEvents:UIControlEventValueChanged]; } - (void)initExtendEvent { self.pageNumberText.delegate = self; } #pragma mark - Accessors - (NSArray *)dataArray { if (!_dataArray) { _dataArray = [NSMutableArray array]; NSArray *pageFormatArray = [[NSArray alloc] initWithObjects:@"1",@"page 1",@"1/n",@"1 of n",@"page 1 of n",nil]; for (int i = 0; i < pageFormatArray.count; i++) { [_dataArray addObject:pageFormatArray[i]]; } } return _dataArray; } #pragma mark - UITextFieldDelegate // TableView initialize - (void)textFieldDidBeginEditing:(UITextField *)textField { if (_pageNumberText == textField) { self.tableView.delegate = self; self.tableView.dataSource = self; [_okBtn setTitle:@" " forState:UIControlStateNormal]; _pageFormatView.hidden = NO; [self.okBtn addTarget:self action:@selector(pageFormatOk:) forControlEvents:UIControlEventTouchUpInside]; } } - (void)textFieldDidChangeSelection:(UITextField *)textField { if (_pageNumberText == textField) { _pageFormatView.hidden = NO; } } - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if (_fontSizeText == textField || _pageIndexNumberText == textField) { return [self validateValue:string]; } return YES; } - (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; } #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pageFormat"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"pageFormat"]; } cell.textLabel.text = self.dataArray[indexPath.row]; return cell; } #pragma mark - UITableViewDelegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { self.modelData.fontSelcet = indexPath.row; self.preLabel1.text = self.dataArray[indexPath.row]; self.preLabel2.text = self.dataArray[indexPath.row]; self.preLabel3.text = self.dataArray[indexPath.row]; self.preLabel4.text = self.dataArray[indexPath.row]; self.preLabel5.text = self.dataArray[indexPath.row]; self.preLabel.text = self.dataArray[indexPath.row]; } #pragma mark - Actions // Candel button enable - (void)cancelClick:(UIBarButtonItem *)btn { [self.navigationController popViewControllerAnimated:YES]; } // Done button enable - (void)doneClick:(UIBarButtonItem *)btn { if ([self.delegate respondsToSelector:@selector(PDFViewPerformChangeHeaderFooter:)]) { [self.delegate PDFViewPerformChangeHeaderFooter:self.modelData]; } [self.navigationController popViewControllerAnimated:YES]; } - (void)pageFormatOk:(UIButton *)okBtn { self.pageNumberText.text = self.preLabel.text; // [self.pageFormat removeFromSuperview]; _pageFormatView.hidden = YES; } #pragma mark - UI Functions - (IBAction)colorSliderChange:(UISlider*)sender { switch ((int)sender.value / 10) { case 0: self.preLabel1.textColor = [UIColor redColor]; self.preLabel2.textColor = [UIColor redColor]; self.preLabel3.textColor = [UIColor redColor]; self.preLabel4.textColor = [UIColor redColor]; self.preLabel5.textColor = [UIColor redColor]; self.preLabel.textColor = [UIColor redColor]; self.modelData.fontColor = [UIColor redColor]; break; case 1: self.preLabel1.textColor = [UIColor orangeColor]; self.preLabel2.textColor = [UIColor orangeColor]; self.preLabel3.textColor = [UIColor orangeColor]; self.preLabel4.textColor = [UIColor orangeColor]; self.preLabel5.textColor = [UIColor orangeColor]; self.preLabel.textColor = [UIColor orangeColor]; self.modelData.fontColor = [UIColor orangeColor]; break; case 2: self.preLabel1.textColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1]; self.preLabel2.textColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1]; self.preLabel3.textColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1]; self.preLabel4.textColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1]; self.preLabel5.textColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1]; self.preLabel.textColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1]; self.modelData.fontColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1]; break; case 3: self.preLabel1.textColor = [UIColor yellowColor]; self.preLabel2.textColor = [UIColor yellowColor]; self.preLabel3.textColor = [UIColor yellowColor]; self.preLabel4.textColor = [UIColor yellowColor]; self.preLabel5.textColor = [UIColor yellowColor]; self.preLabel.textColor = [UIColor yellowColor]; self.modelData.fontColor = [UIColor yellowColor];; break; case 4: self.preLabel1.textColor = [UIColor greenColor]; self.preLabel2.textColor = [UIColor greenColor]; self.preLabel3.textColor = [UIColor greenColor]; self.preLabel4.textColor = [UIColor greenColor]; self.preLabel5.textColor = [UIColor greenColor]; self.preLabel.textColor = [UIColor greenColor]; self.modelData.fontColor = [UIColor greenColor]; break; case 5: self.preLabel1.textColor = [UIColor blueColor]; self.preLabel2.textColor = [UIColor blueColor]; self.preLabel3.textColor = [UIColor blueColor]; self.preLabel4.textColor = [UIColor blueColor]; self.preLabel5.textColor = [UIColor blueColor]; self.preLabel.textColor = [UIColor blueColor]; self.modelData.fontColor = [UIColor blueColor]; break; case 6: self.preLabel1.textColor = [UIColor purpleColor]; self.preLabel2.textColor = [UIColor purpleColor]; self.preLabel3.textColor = [UIColor purpleColor]; self.preLabel4.textColor = [UIColor purpleColor]; self.preLabel5.textColor = [UIColor purpleColor]; self.preLabel.textColor = [UIColor purpleColor]; self.modelData.fontColor = [UIColor purpleColor]; break; case 7: self.preLabel1.textColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1]; self.preLabel2.textColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1]; self.preLabel3.textColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1]; self.preLabel4.textColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1]; self.preLabel5.textColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1]; self.preLabel.textColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1]; self.modelData.fontColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1]; break; case 8: self.preLabel1.textColor = [UIColor blackColor]; self.preLabel2.textColor = [UIColor blackColor]; self.preLabel3.textColor = [UIColor blackColor]; self.preLabel4.textColor = [UIColor blackColor]; self.preLabel5.textColor = [UIColor blackColor]; self.preLabel.textColor = [UIColor blackColor]; self.modelData.fontColor = [UIColor blackColor]; break; case 9: self.preLabel1.textColor = [UIColor whiteColor]; self.preLabel2.textColor = [UIColor whiteColor]; self.preLabel3.textColor = [UIColor whiteColor]; self.preLabel4.textColor = [UIColor whiteColor]; self.preLabel5.textColor = [UIColor whiteColor]; self.preLabel.textColor = [UIColor whiteColor]; self.modelData.fontColor = [UIColor whiteColor]; break; default: break; } } //- (void)sliderChange:(UISlider *)slider { // //} - (void)showPages { switch (self.position.location) { case PDFHeaderFooterLocationHeader: if (self.position.aligment == PDFHeaderFooerAligmentLeft) { _preLabel1.hidden = NO; _preLabel2.hidden = YES; _preLabel3.hidden = YES; _preLabel4.hidden = YES; _preLabel5.hidden = YES; _preLabel.hidden = YES; self.modelData.fontPosition = 0; } else if (self.position.aligment == PDFHeaderFooerAligmentCenter) { _preLabel1.hidden = YES; _preLabel2.hidden = NO; _preLabel3.hidden = YES; _preLabel4.hidden = YES; _preLabel5.hidden = YES; _preLabel.hidden = YES; self.modelData.fontPosition = 1; } else { _preLabel1.hidden = YES; _preLabel2.hidden = YES; _preLabel3.hidden = NO; _preLabel4.hidden = YES; _preLabel5.hidden = YES; _preLabel.hidden = YES; self.modelData.fontPosition = 2; } break; case PDFHeaderFooterLocationFooter: if (self.position.aligment == PDFHeaderFooerAligmentLeft) { _preLabel1.hidden = YES; _preLabel2.hidden = YES; _preLabel3.hidden = YES; _preLabel4.hidden = NO; _preLabel5.hidden = YES; _preLabel.hidden = YES; self.modelData.fontPosition = 3; } else if (self.position.aligment == PDFHeaderFooerAligmentCenter) { _preLabel1.hidden = YES; _preLabel2.hidden = YES; _preLabel3.hidden = YES; _preLabel4.hidden = YES; _preLabel5.hidden = NO; _preLabel.hidden = YES; self.modelData.fontPosition = 4; } else { _preLabel1.hidden = YES; _preLabel2.hidden = YES; _preLabel3.hidden = YES; _preLabel4.hidden = YES; _preLabel5.hidden = YES; _preLabel.hidden = NO; self.modelData.fontPosition = 5; } break; default: break; } } - (IBAction)changePageStart:(UITextField *)sender { int start = [sender.text intValue]; self.modelData.pageStart = [NSString stringWithFormat:@"%d",start]; } - (IBAction)changeFontSize:(UITextField*)sender { float size = [sender.text floatValue]; self.preLabel1.font = [UIFont systemFontOfSize:size / 3]; self.preLabel2.font = [UIFont systemFontOfSize:size / 3]; self.preLabel3.font = [UIFont systemFontOfSize:size / 3]; self.preLabel4.font = [UIFont systemFontOfSize:size / 3]; self.preLabel5.font = [UIFont systemFontOfSize:size / 3]; self.preLabel.font = [UIFont systemFontOfSize:size / 3]; self.modelData.fontSize = size; } - (IBAction)PDFHeaderFooterAddViewUp:(id)sender { if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown) { } else { [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ { self.headerFooterView.center = CGPointMake(self.headerFooterView.center.x, self.headerFooterView.center.y - 300); } completion:nil]; } } - (IBAction)PDFHeaderFooterAddViewDown:(id)sender { if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown) { } else { [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ { self.headerFooterView.center = CGPointMake(self.headerFooterView.center.x, self.headerFooterView.center.y + 300); } completion:nil]; } } @end