123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- //
- // 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
|