// // BatesAddViewController.m // PDFViewer // // Created by kdanmobile_2 on 2022/11/18. // #import "CPDFBatesAddViewController.h" @interface CPDFBatesAddViewController () @end @implementation CPDFBatesAddViewController - (id)initWithIamge:(UIImage *)image WithSize:(CGSize)size { self = [super init]; if (self) { _image = image; _size = size; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.navigationItem.title = @"Add Bates"; self.navigationController.toolbarHidden = NO; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneBatesClick:)]; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelClick:)]; //initialize model _modelBatesData = [[CPDFBatesModel alloc] init]; //add page image _imageView = [[UIImageView alloc] init]; _imageView.image = self.image; CALayer *layer = [_imageView layer]; layer.borderColor = [[UIColor blackColor] CGColor]; layer.borderWidth = 0.5f; [self.view addSubview:_imageView]; _batesAddView = [[CPDFBatesAddView alloc] init]; [self.view addSubview:_batesAddView]; [_imageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view.mas_top).offset(125); make.left.equalTo(self.view.mas_left).offset((393/2)-(self.size.width/6)); make.width.mas_equalTo(self.size.width/3); make.height.mas_equalTo(self.size.height/3); }]; //add view [self.batesAddView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.imageView.mas_bottom).offset(60); make.left.equalTo(self.view.mas_left); make.width.mas_equalTo(self.view.frame.size.width); make.height.mas_equalTo(self.view.frame.size.height); }]; [ _batesAddView.localSegment addTarget:self action:@selector(changeLocation:) forControlEvents:UIControlEventValueChanged]; [ _batesAddView.aligbmentSegment addTarget:self action:@selector(changeAligbment:) forControlEvents:UIControlEventValueChanged]; [ _batesAddView.colorSlider addTarget:self action:@selector(sliderChange:) forControlEvents:UIControlEventValueChanged]; [_batesAddView.pageIndexNumberText addTarget:self action:@selector(changePageStart:) forControlEvents:UIControlEventEditingChanged]; [_batesAddView.pageNumberText addTarget:self action:@selector(changeText:) forControlEvents:UIControlEventEditingChanged]; [_batesAddView.fontNameText addTarget:self action:@selector(changeFontname:) forControlEvents:UIControlEventEditingChanged]; } - (void)doneBatesClick:(UIBarButtonItem *)btn { NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:self.modelBatesData,@"batesModel", nil]; NSNotification *notification = [NSNotification notificationWithName:@"getAddBatesModel" object:nil userInfo:dict]; [[NSNotificationCenter defaultCenter] postNotification:notification]; [self.navigationController popViewControllerAnimated:YES]; } - (void)cancelClick:(UIBarButtonItem *)btn { [self.navigationController popViewControllerAnimated:YES]; } - (void)changeText:(UITextField *)text { self.showLabel.text = text.text; self.modelBatesData.fontText = text.text; } - (void)changePageStart:(UITextField *)text { int start = [text.text intValue]; self.modelBatesData.pageStart = [NSString stringWithFormat:@"%d",start - 1]; } - (void)changeFontname:(UITextField *)fontName { self.showLabel.font = [UIFont fontWithName:fontName.text size:5]; self.modelBatesData.fontName = fontName.text; self.modelBatesData.fontSize = 15; } //slider select color - (void)sliderChange:(UISlider *)slider { switch ((int)slider.value/10) { case 0: self.showLabel.textColor = [UIColor redColor]; self.modelBatesData.fontColor = [UIColor redColor]; break; case 1: self.showLabel.textColor = [UIColor orangeColor]; self.modelBatesData.fontColor = [UIColor orangeColor]; break; case 2: self.showLabel.textColor = [UIColor colorWithRed:239.0/255 green:140.0/255 blue:133.0/255 alpha:1]; self.modelBatesData.fontColor = [UIColor colorWithRed:239.0/255 green:140.0/255 blue:133.0/255 alpha:1]; break; case 3: self.showLabel.textColor = [UIColor yellowColor]; self.modelBatesData.fontColor = [UIColor yellowColor]; break; case 4: self.showLabel.textColor = [UIColor greenColor]; self.modelBatesData.fontColor = [UIColor greenColor]; break; case 5: self.showLabel.textColor = [UIColor blueColor]; self.modelBatesData.fontColor = [UIColor blueColor]; break; case 6: self.showLabel.textColor = [UIColor purpleColor]; self.modelBatesData.fontColor = [UIColor purpleColor]; break; case 7: self.showLabel.textColor = [UIColor colorWithRed:235.0/255 green:61.0/255 blue:133.0/255 alpha:1]; self.modelBatesData.fontColor = [UIColor colorWithRed:235.0/255 green:61.0/255 blue:133.0/255 alpha:1]; break; case 8: self.showLabel.textColor = [UIColor blackColor]; self.modelBatesData.fontColor = [UIColor blackColor]; break; default: break; } } //select headerfooter - (void)changeLocation:(UISegmentedControl *)sender { if (sender.selectedSegmentIndex == 0) { _position.location = kHeader; } else { _position.location = kFooter; } [self showPages]; } //select aligment - (void)changeAligbment:(UISegmentedControl *)sender { if (sender.selectedSegmentIndex == 0) { _position.aligment = kLeft; } else if (sender.selectedSegmentIndex == 1) { _position.aligment = kCenter; } else { _position.aligment = kRinght; } [self showPages]; } //show headerfooter and aligment - (void)showPages { if (_showLabel == nil) { _showLabel = [[UILabel alloc] init]; } [_showLabel setText:@"0016"]; _showLabel.font = [UIFont systemFontOfSize:5]; [self.imageView addSubview:self.showLabel]; switch (self.position.location) { case kHeader: if (self.position.aligment == kLeft) { [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(_imageView.mas_top).offset(1); make.left.equalTo(self.imageView.mas_left).offset(1); make.height.mas_equalTo(5); make.width.mas_equalTo(20); }]; self.modelBatesData.fontPosition = 0; } else if (self.position.aligment == kCenter) { [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(_imageView.mas_top).offset(1); make.left.equalTo(self.imageView.mas_left).offset(self.size.width / 6); make.height.mas_equalTo(5); make.width.mas_equalTo(20); }]; self.modelBatesData.fontPosition = 1; } else { [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.imageView.mas_top).offset(0.5); make.left.equalTo(self.imageView.mas_left).offset(self.size.width / 3 - 12); make.height.mas_equalTo(5); make.width.mas_equalTo(20); }]; self.modelBatesData.fontPosition = 2; } break; case kFooter: if (self.position.aligment == kLeft) { [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.imageView.mas_top).offset(self.size.height / 3 - 12); make.left.equalTo(self.imageView.mas_left).offset(0.5); make.height.mas_equalTo(5); make.width.mas_equalTo(20); }]; self.modelBatesData.fontPosition = 3; } else if (self.position.aligment == kCenter) { [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.imageView.mas_top).offset(self.size.height / 3 - 12); make.left.equalTo(self.imageView.mas_left).offset(self.size.width/6); make.height.mas_equalTo(5); make.width.mas_equalTo(20); }]; self.modelBatesData.fontPosition = 4; } else { [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.imageView.mas_top).offset(self.size.height / 3 - 12); make.left.equalTo(self.imageView.mas_left).offset(self.size.width / 3 - 12); make.height.mas_equalTo(5); make.width.mas_equalTo(20); }]; self.modelBatesData.fontPosition = 5; } break; default: break; } } - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) { [_imageView mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view.mas_top).offset((393/2)-(self.size.height/6)); make.left.equalTo(self.view.mas_left).offset((393/2)-(self.size.width/6)); make.width.mas_equalTo(self.size.width/3); make.height.mas_equalTo(self.size.height/3); }]; //add view [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view.mas_top).offset(15); make.left.equalTo(self.view.mas_left).offset(self.view.frame.size.width / 2 + 200); make.width.mas_equalTo(393); make.height.mas_equalTo(self.view.frame.size.height - 20); }]; } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) { [_imageView mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view.mas_top).offset(125); make.left.equalTo(self.view.mas_left).offset((393 / 2)-(self.size.width / 6)); make.width.mas_equalTo(self.size.width / 3); make.height.mas_equalTo(self.size.height / 3); }]; //add view [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.imageView.mas_bottom).offset(60); make.left.equalTo(self.view.mas_left); make.width.mas_equalTo(self.view.frame.size.width); make.height.mas_equalTo(self.view.frame.size.height); }]; } } @end