CPDFBatesAddViewController.m 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. //
  2. // BatesAddViewController.m
  3. // PDFViewer
  4. //
  5. // Created by kdanmobile_2 on 2022/11/18.
  6. //
  7. #import "CPDFBatesAddViewController.h"
  8. @interface CPDFBatesAddViewController ()
  9. @property (nonatomic,strong) CPDFHeaderFooterTextTableView *fontName;
  10. @property (nonatomic,strong) NSMutableArray *dataArray;
  11. @property (nonatomic,strong) CPDFBatesAddView *batesAddView;
  12. @end
  13. @implementation CPDFBatesAddViewController
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. // Do any additional setup after loading the view.
  17. }
  18. #pragma mark - Initializers
  19. - (void)initNavigation {
  20. self.navigationItem.title = @"Add Bates";
  21. self.navigationController.toolbarHidden = YES;
  22. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneBatesClick:)];
  23. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelClick:)];
  24. }
  25. - (void)initModel {
  26. self.modelData = [[CPDFHeaderFooterModel alloc] init];
  27. self.modelData.fontName = @"Helvetica";
  28. self.modelData.fontPosition = 1;
  29. self.modelData.fontText = @"#2#1#0#0";
  30. self.modelData.fontColor = [UIColor blackColor];
  31. }
  32. - (void)initShowLabel {
  33. self.showLabel = [[UILabel alloc] init];
  34. [self.showLabel setText:@"0010"];
  35. self.showLabel.font = [UIFont systemFontOfSize:5];
  36. }
  37. - (void)initBttonmView {
  38. _batesAddView = [[CPDFBatesAddView alloc] init];
  39. [_batesAddView setText];
  40. [self.view addSubview:_batesAddView];
  41. [self.batesAddView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.top.equalTo(self.imageView.mas_bottom).offset(60);
  43. make.left.equalTo(self.view.mas_left);
  44. make.width.mas_equalTo(self.view.frame.size.width);
  45. make.height.mas_equalTo(self.view.frame.size.height);
  46. }];
  47. }
  48. - (void)initBasicEvent {
  49. [_batesAddView.localSegment addTarget:self action:@selector(changeLocation:) forControlEvents:UIControlEventValueChanged];
  50. [_batesAddView.aligbmentSegment addTarget:self action:@selector(changeAligbment:) forControlEvents:UIControlEventValueChanged];
  51. [_batesAddView.colorSlider addTarget:self action:@selector(sliderChange:) forControlEvents:UIControlEventValueChanged];
  52. }
  53. - (void)initExtendEvent {
  54. [_batesAddView.pageIndexNumberText addTarget:self action:@selector(changePageStart:) forControlEvents:UIControlEventEditingChanged];
  55. [_batesAddView.pageNumberText addTarget:self action:@selector(changeText:) forControlEvents:UIControlEventEditingChanged];
  56. _batesAddView.fontNameText.delegate = self;
  57. }
  58. #pragma mark - Accessors
  59. - (NSArray *)dataArray {
  60. if (!_dataArray) {
  61. _dataArray = [NSMutableArray array];
  62. NSArray *fontNameArray = [[NSArray alloc] initWithObjects:@"Helvetica",@"Arial",@"Arial Rounded MT Bold", @"Arial Unicode MS",@"Courier",nil];
  63. for (int i = 0; i < fontNameArray.count; i++) {
  64. [_dataArray addObject:fontNameArray[i]];
  65. }
  66. }
  67. return _dataArray;
  68. }
  69. #pragma mark - UITextFieldDelegate
  70. - (void)textFieldDidBeginEditing:(UITextField *)textField {
  71. _fontName = [[CPDFHeaderFooterTextTableView alloc] initWithTitleName:@"Font Name"];
  72. _fontName.tableView.delegate = self;
  73. _fontName.tableView.dataSource = self;
  74. [self.batesAddView addSubview:self.fontName ];
  75. [self.view bringSubviewToFront:self.fontName];
  76. [_fontName mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.top.equalTo(self.batesAddView.mas_top).offset(50);
  78. make.left.equalTo(self.batesAddView.mas_left).offset(50);
  79. make.width.mas_equalTo(293);
  80. make.height.mas_equalTo(300);
  81. }];
  82. [self.fontName.okBtn addTarget:self action:@selector(fontNameOk:) forControlEvents:UIControlEventTouchUpInside];
  83. }
  84. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  85. return NO;
  86. }
  87. #pragma mark - UITableViewDataSource
  88. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  89. return self.dataArray.count;
  90. }
  91. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  92. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pageFormat"];
  93. if (cell == nil) {
  94. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"pageFormat"];
  95. }
  96. cell.textLabel.text = self.dataArray[indexPath.row];
  97. return cell;
  98. }
  99. #pragma mark - UITableViewDelegate
  100. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  101. self.batesAddView.fontNameText.text = self.dataArray[indexPath.row];
  102. self.modelData.fontName = self.dataArray[indexPath.row];
  103. self.showLabel.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
  104. }
  105. #pragma mark - Actions
  106. // Done button enable
  107. - (void)doneBatesClick:(UIBarButtonItem *)btn {
  108. if ([self.delegate respondsToSelector:@selector(changBatesModelData:)]) {
  109. [self.delegate changBatesModelData:self.modelData];
  110. }
  111. [self.navigationController popViewControllerAnimated:YES];
  112. }
  113. // Candel button enable
  114. - (void)cancelClick:(UIBarButtonItem *)btn {
  115. [self.navigationController popViewControllerAnimated:YES];
  116. }
  117. - (void)fontNameOk:(UIButton *)okBtn {
  118. [_fontName removeFromSuperview];
  119. }
  120. #pragma mark - UI Functions
  121. // Get page text for bates's model
  122. - (void)changeText:(UITextField *)text {
  123. NSArray *textArray = [text.text componentsSeparatedByString:@"#"];
  124. NSString *showText = [[NSString alloc] init];
  125. if (text.text.length >= 2) {
  126. int i = [textArray[1] intValue];
  127. for (int j = 0; j < i-1; j++) {
  128. NSString *test = showText;
  129. showText = [NSString stringWithFormat:@"%d%@",0,test];
  130. }
  131. }
  132. if (text.text.length >= 4) {
  133. showText = [NSString stringWithFormat:@"%@%@",showText,textArray[2]];
  134. }
  135. if (text.text.length >= 6) {
  136. showText = [NSString stringWithFormat:@"%@%@",textArray[3],showText];
  137. }
  138. if (text.text.length == 8) {
  139. showText = [NSString stringWithFormat:@"%@%@",showText,textArray[4]];
  140. }
  141. self.showLabel.text = showText;
  142. self.modelData.fontText = text.text;
  143. }
  144. // Get page text start for bates's model
  145. - (void)changePageStart:(UITextField *)text {
  146. int start = [text.text intValue];
  147. self.modelData.pageStart = [NSString stringWithFormat:@"%d",start - 1];
  148. }
  149. #pragma mark - Orientation
  150. // When orientation
  151. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  152. if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
  153. [self.imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
  154. make.top.equalTo(self.view.mas_top).offset((393 / 2) - (self.size.height / 6));
  155. make.left.equalTo(self.view.mas_left).offset((393 / 2) - (self.size.width / 6));
  156. make.width.mas_equalTo(self.size.width / 3);
  157. make.height.mas_equalTo(self.size.height / 3);
  158. }];
  159. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  160. make.top.equalTo(self.view.mas_top).offset(15);
  161. make.left.equalTo(self.view.mas_left).offset(self.view.frame.size.width / 2 + 200);
  162. make.width.mas_equalTo(393);
  163. make.height.mas_equalTo(self.view.frame.size.height - 20);
  164. }];
  165. } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
  166. [self.imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
  167. make.top.equalTo(self.view.mas_top).offset(125);
  168. make.left.equalTo(self.view.mas_left).offset((393 / 2) - (self.size.width / 6));
  169. make.width.mas_equalTo(self.size.width / 3);
  170. make.height.mas_equalTo(self.size.height / 3);
  171. }];
  172. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  173. make.top.equalTo(self.imageView.mas_bottom).offset(60);
  174. make.left.equalTo(self.view.mas_left);
  175. make.width.mas_equalTo(self.view.frame.size.width);
  176. make.height.mas_equalTo(self.view.frame.size.height);
  177. }];
  178. }
  179. }
  180. @end