CPDFBatesAddViewController.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. CPDFFontNameModel *fontNameModel = [[CPDFFontNameModel alloc] init];
  65. fontNameModel.fontName = fontNameArray[i];
  66. [_dataArray addObject:fontNameModel];
  67. }
  68. }
  69. return _dataArray;
  70. }
  71. #pragma mark - UITextFieldDelegate
  72. - (void)textFieldDidBeginEditing:(UITextField *)textField {
  73. _fontName = [[CPDFHeaderFooterTextTableView alloc] initWithTitleName:@"Font Name"];
  74. _fontName.tableView.delegate = self;
  75. _fontName.tableView.dataSource = self;
  76. [self.batesAddView addSubview:self.fontName ];
  77. [self.view bringSubviewToFront:self.fontName];
  78. [_fontName mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.top.equalTo(self.batesAddView.mas_top).offset(50);
  80. make.left.equalTo(self.batesAddView.mas_left).offset(50);
  81. make.width.mas_equalTo(293);
  82. make.height.mas_equalTo(300);
  83. }];
  84. [self.fontName.okBtn addTarget:self action:@selector(fontNameOk:) forControlEvents:UIControlEventTouchUpInside];
  85. }
  86. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  87. return NO;
  88. }
  89. #pragma mark - UITableViewDataSource
  90. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  91. return self.dataArray.count;
  92. }
  93. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  94. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pageFormat"];
  95. if (cell == nil) {
  96. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"pageFormat"];
  97. }
  98. cell.textLabel.text = [self.dataArray[indexPath.row] fontName];
  99. return cell;
  100. }
  101. #pragma mark - UITableViewDelegate
  102. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  103. self.batesAddView.fontNameText.text = [self.dataArray[indexPath.row] fontName];
  104. self.modelData.fontName = [self.dataArray[indexPath.row] fontName];
  105. self.showLabel.font = [UIFont fontWithName:[self.dataArray[indexPath.row] fontName] size:5];
  106. }
  107. #pragma mark - Actions
  108. // Done button enable
  109. - (void)doneBatesClick:(UIBarButtonItem *)btn {
  110. NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:self.modelData,@"batesModel", nil];
  111. NSNotification *notification = [NSNotification notificationWithName:@"getAddBatesModel" object:nil userInfo:dict];
  112. [[NSNotificationCenter defaultCenter] postNotification:notification];
  113. [self.navigationController popViewControllerAnimated:YES];
  114. }
  115. // Candel button enable
  116. - (void)cancelClick:(UIBarButtonItem *)btn {
  117. [self.navigationController popViewControllerAnimated:YES];
  118. }
  119. - (void)fontNameOk:(UIButton *)okBtn {
  120. [_fontName removeFromSuperview];
  121. }
  122. #pragma mark - UI Actions
  123. // Get page text for bates's model
  124. - (void)changeText:(UITextField *)text {
  125. NSArray *textArray = [text.text componentsSeparatedByString:@"#"];
  126. NSString *showText = [[NSString alloc] init];
  127. if (text.text.length >= 2) {
  128. int i = [textArray[1] intValue];
  129. for (int j = 0; j < i-1; j++) {
  130. NSString *test = showText;
  131. showText = [NSString stringWithFormat:@"%d%@",0,test];
  132. }
  133. }
  134. if (text.text.length >= 4) {
  135. showText = [NSString stringWithFormat:@"%@%@",showText,textArray[2]];
  136. }
  137. if (text.text.length >= 6) {
  138. showText = [NSString stringWithFormat:@"%@%@",textArray[3],showText];
  139. }
  140. if (text.text.length == 8) {
  141. showText = [NSString stringWithFormat:@"%@%@",showText,textArray[4]];
  142. }
  143. self.showLabel.text = showText;
  144. self.modelData.fontText = text.text;
  145. }
  146. // Get page text start for bates's model
  147. - (void)changePageStart:(UITextField *)text {
  148. int start = [text.text intValue];
  149. self.modelData.pageStart = [NSString stringWithFormat:@"%d",start - 1];
  150. }
  151. #pragma mark - Orientation
  152. // When orientation
  153. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  154. if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
  155. [self.imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
  156. make.top.equalTo(self.view.mas_top).offset((393 / 2) - (self.size.height / 6));
  157. make.left.equalTo(self.view.mas_left).offset((393 / 2) - (self.size.width / 6));
  158. make.width.mas_equalTo(self.size.width / 3);
  159. make.height.mas_equalTo(self.size.height / 3);
  160. }];
  161. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  162. make.top.equalTo(self.view.mas_top).offset(15);
  163. make.left.equalTo(self.view.mas_left).offset(self.view.frame.size.width / 2 + 200);
  164. make.width.mas_equalTo(393);
  165. make.height.mas_equalTo(self.view.frame.size.height - 20);
  166. }];
  167. } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
  168. [self.imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
  169. make.top.equalTo(self.view.mas_top).offset(125);
  170. make.left.equalTo(self.view.mas_left).offset((393 / 2) - (self.size.width / 6));
  171. make.width.mas_equalTo(self.size.width / 3);
  172. make.height.mas_equalTo(self.size.height / 3);
  173. }];
  174. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  175. make.top.equalTo(self.imageView.mas_bottom).offset(60);
  176. make.left.equalTo(self.view.mas_left);
  177. make.width.mas_equalTo(self.view.frame.size.width);
  178. make.height.mas_equalTo(self.view.frame.size.height);
  179. }];
  180. }
  181. }
  182. @end