123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- //
- // 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 = 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:)];
-
- // Initialize model
- _modelBatesData = [[CPDFBatesModel alloc] init];
- _modelBatesData.fontName = @"Helvetica";
- _modelBatesData.fontPosition = 1;
- _modelBatesData.fontText = @"#2#1#0#0";
- _modelBatesData.fontColor = [UIColor blackColor];
-
- // 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);
- }];
-
- // UI event
- [ _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.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++) {
- CPDFFontNameModel *fontNameModel = [[CPDFFontNameModel alloc] init];
- fontNameModel.fontName = fontNameArray[i];
- [_dataArray addObject:fontNameModel];
- }
- }
- return _dataArray;
- }
- #pragma mark - UITextFieldDelegate
- - (void)textFieldDidBeginEditing:(UITextField *)textField {
- _fontName = [[CPDFHeaderFooterTextTableView alloc] initWithTitleName:@"Font Name"];
-
- _fontName.tableView.delegate = self;
- _fontName.tableView.dataSource = self;
-
- [self.batesAddView addSubview:self.fontName ];
- [self.view bringSubviewToFront:self.fontName];
- [_fontName mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.batesAddView.mas_top).offset(50);
- make.left.equalTo(self.batesAddView.mas_left).offset(50);
- make.width.mas_equalTo(293);
- make.height.mas_equalTo(300);
- }];
-
- [self.fontName.okBtn addTarget:self action:@selector(fontNameOk:) forControlEvents:UIControlEventTouchUpInside];
- }
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
- return NO;
- }
- #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] fontName];
- return cell;
- }
- #pragma mark - UITableViewDelegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- self.batesAddView.fontNameText.text = [self.dataArray[indexPath.row] fontName];
-
- self.modelBatesData.fontName = [self.dataArray[indexPath.row] fontName];
-
- self.showLabel.font = [UIFont fontWithName:[self.dataArray[indexPath.row] fontName] size:5];
- }
- #pragma mark - Actions
- // Done button enable
- - (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];
- }
- // Candel button enable
- - (void)cancelClick:(UIBarButtonItem *)btn {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)fontNameOk:(UIButton *)okBtn {
- [_fontName removeFromSuperview];
- }
- #pragma mark - UI Actions
- // Get page text for bates's model
- - (void)changeText:(UITextField *)text {
- NSArray *textArray = [text.text componentsSeparatedByString:@"#"];
- NSString *showText = [[NSString alloc] init];
-
- if (text.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 (text.text.length >= 4) {
- showText = [NSString stringWithFormat:@"%@%@",showText,textArray[2]];
- }
- if (text.text.length >= 6) {
- showText = [NSString stringWithFormat:@"%@%@",textArray[3],showText];
- }
- if (text.text.length == 8) {
- showText = [NSString stringWithFormat:@"%@%@",showText,textArray[4]];
- }
-
- self.showLabel.text = showText;
- self.modelBatesData.fontText = text.text;
- }
- // Get page text start for bates's model
- - (void)changePageStart:(UITextField *)text {
- int start = [text.text intValue];
- self.modelBatesData.pageStart = [NSString stringWithFormat:@"%d",start - 1];
- }
- // 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:@"2100"];
- _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(30);
- }];
- 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(30);
- }];
- 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(30);
- }];
- 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(30);
- }];
- 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(30);
- }];
- 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(30);
- }];
- self.modelBatesData.fontPosition = 5;
- }
- break;
- default:
- break;
- }
- }
- #pragma mark - Orientation
- // When orientation
- - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)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);
- }];
-
- [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);
- }];
-
- [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
|