123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- //
- // BatesAddViewController.m
- // PDFViewer
- //
- // Created by kdanmobile_2 on 2022/11/18.
- //
- #import "PDFBatesAddViewController.h"
- #import "PDFAddViewControllerHeader.h"
- @interface PDFBatesAddViewController ()
- @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 *fontNameLabel;
- @property (retain, nonatomic) IBOutlet UITextField *fontNameText;
- @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 UILabel *titleView;
- @property (retain, nonatomic) IBOutlet UIButton *okBtn;
- @property (retain, nonatomic) IBOutlet UITableView *tableView;
- @property (retain, nonatomic) IBOutlet UIView *pageFormatView;
- @property (retain, nonatomic) IBOutlet UIView *batesAddView;
- //@property (nonatomic,strong) PDFHeaderFooterTextTableView *fontName;
- @property (nonatomic,strong) NSMutableArray *dataArray;
- //@property (nonatomic,strong) PDFBatesAddView *batesAddView;
- @end
- @implementation PDFBatesAddViewController
- #pragma mark - UIViewController Methods
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self initHeadView];
- [self initButtonView];
- }
- - (void)viewDidLayoutSubviews {
- [super viewDidLayoutSubviews];
-
- [self initBasicEvent];
- [self initExtendEvent];
- }
- - (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 {
- _tableView.delegate = self;
- _tableView.dataSource = self;
-
- [_okBtn setTitle:@" " forState:UIControlStateNormal];
- }
- #pragma mark - Initializers
- - (void)initNavigation {
- self.navigationItem.title = NSLocalizedString(@"Add Bates", nil);
- self.navigationController.toolbarHidden = YES;
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneBatesClick:)];
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelClick:)];
- }
- - (void)initModel {
- self.modelData = [[PDFHeaderFooterModel alloc] init];
- self.modelData.fontName = @"Helvetica";
- self.modelData.fontPosition = 0;
- self.modelData.fontText = @"#2#1#0#0";
- self.modelData.fontColor = [UIColor blackColor];
- }
- - (void)initBasicEvent {
- [_localSegment addTarget:self action:@selector(changeLocation:) forControlEvents:UIControlEventValueChanged];
- [_aligbmentSegment addTarget:self action:@selector(changeAligbment:) forControlEvents:UIControlEventValueChanged];
- }
- - (void)initExtendEvent {
- _fontNameText.delegate = self;
- }
- #pragma mark - Accessors
- - (NSArray *)dataArray {
- if (!_dataArray) {
- _dataArray = [NSMutableArray array];
- NSArray *fontNameArray = [[NSArray alloc] initWithObjects:@"Helvetica",@"Arial",@"Arial Rounded MT Bold", @"Arial Unicode MS",@"Courier",nil];
-
- for (int i = 0; i < fontNameArray.count; i++) {
- [_dataArray addObject:fontNameArray[i]];
- }
- }
- return _dataArray;
- }
- #pragma mark - UITextFieldDelegate
- - (void)textFieldDidBeginEditing:(UITextField *)textField {
- if (_fontNameText == textField) {
- _pageFormatView.hidden = NO;
-
- [self.okBtn addTarget:self action:@selector(fontNameOk:) forControlEvents:UIControlEventTouchUpInside];
- }
- }
- - (void)textFieldDidChangeSelection:(UITextField *)textField {
- if (_fontNameText == textField) {
- _pageFormatView.hidden = NO;
- }
- }
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- [textField resignFirstResponder];
- return YES;
- }
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
- if (_pageNumberText == 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:@"fontName"];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"fontName"];
- }
-
- cell.textLabel.text = self.dataArray[indexPath.row];
- return cell;
- }
- #pragma mark - UITableViewDelegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- self.modelData.fontName = self.dataArray[indexPath.row];
-
- self.preLabel1.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
- self.preLabel2.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
- self.preLabel3.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
- self.preLabel4.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
- self.preLabel5.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
- self.preLabel.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
- }
- #pragma mark - Actions
- // Done button enable
- - (void)doneBatesClick:(UIBarButtonItem *)btn {
- if ([self.delegate respondsToSelector:@selector(PDFViewPerformChangBates:)]) {
- [self.delegate PDFViewPerformChangBates:self.modelData];
- }
- [self.navigationController popViewControllerAnimated:YES];
- }
- // Candel button enable
- - (void)cancelClick:(UIBarButtonItem *)btn {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)fontNameOk:(UIButton *)okBtn {
- self.fontNameText.text = self.modelData.fontName;
- _pageFormatView.hidden = YES;
-
- // [_fontName removeFromSuperview];
- }
- #pragma mark - UI Functions
- - (IBAction)colorChange:(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)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;
- }
- }
- // Get page text for bates's model
- - (IBAction)changeText:(UITextField *)sender {
- NSArray *textArray = [sender.text componentsSeparatedByString:@"#"];
- NSString *showText = [[NSString alloc] init];
-
- if (sender.text.length >= 2) {
- int i = [textArray[1] intValue];
- for (int j = 0; j < i-1; j++) {
- NSString *test = showText;
- showText = [NSString stringWithFormat:@"%d%@",0,test];
- }
- }
- if (sender.text.length >= 4) {
- showText = [NSString stringWithFormat:@"%@%@",showText,textArray[2]];
- }
- if (sender.text.length >= 6) {
- showText = [NSString stringWithFormat:@"%@%@",textArray[3],showText];
- }
- if (sender.text.length == 8) {
- showText = [NSString stringWithFormat:@"%@%@",showText,textArray[4]];
- }
-
- self.preLabel1.text = showText;
- self.preLabel2.text = showText;
- self.preLabel3.text = showText;
- self.preLabel4.text = showText;
- self.preLabel5.text = showText;
- self.preLabel.text = showText;
- self.modelData.fontText = sender.text;
- }
- // Get page text start for bates's model
- - (IBAction)changePageStart:(UITextField *)sender {
- int start = [sender.text intValue];
- self.modelData.pageStart = [NSString stringWithFormat:@"%d",start - 1];
- }
- - (IBAction)PDFBatesAddViewUp:(UITextField *)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.batesAddView.center = CGPointMake(self.batesAddView.center.x, self.batesAddView.center.y - 300);
- } completion:nil];
- }
- }
- - (IBAction)PDFBatesAddViewDown:(UITextField *)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.batesAddView.center = CGPointMake(self.batesAddView.center.x, self.batesAddView.center.y + 300);
- } completion:nil];
- }
- }
- @end
|