CPDFBatesAddViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. @end
  10. @implementation CPDFBatesAddViewController
  11. - (id)initWithIamge:(UIImage *)image WithSize:(CGSize)size {
  12. self = [super init];
  13. if (self) {
  14. _image = image;
  15. _size = size;
  16. }
  17. return self;
  18. }
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. self.navigationItem.title = @"Add Bates";
  23. self.navigationController.toolbarHidden = NO;
  24. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneBatesClick:)];
  25. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelClick:)];
  26. //initialize model
  27. _modelBatesData = [[CPDFBatesModel alloc] init];
  28. //add page image
  29. _imageView = [[UIImageView alloc] init];
  30. _imageView.image = self.image;
  31. CALayer *layer = [_imageView layer];
  32. layer.borderColor = [[UIColor blackColor] CGColor];
  33. layer.borderWidth = 0.5f;
  34. [self.view addSubview:_imageView];
  35. _batesAddView = [[CPDFBatesAddView alloc] init];
  36. [self.view addSubview:_batesAddView];
  37. [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.top.equalTo(self.view.mas_top).offset(125);
  39. make.left.equalTo(self.view.mas_left).offset((393/2)-(self.size.width/6));
  40. make.width.mas_equalTo(self.size.width/3);
  41. make.height.mas_equalTo(self.size.height/3);
  42. }];
  43. //add view
  44. [self.batesAddView mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.top.equalTo(self.imageView.mas_bottom).offset(60);
  46. make.left.equalTo(self.view.mas_left);
  47. make.width.mas_equalTo(self.view.frame.size.width);
  48. make.height.mas_equalTo(self.view.frame.size.height);
  49. }];
  50. [ _batesAddView.localSegment addTarget:self action:@selector(changeLocation:) forControlEvents:UIControlEventValueChanged];
  51. [ _batesAddView.aligbmentSegment addTarget:self action:@selector(changeAligbment:) forControlEvents:UIControlEventValueChanged];
  52. [ _batesAddView.colorSlider addTarget:self action:@selector(sliderChange:) forControlEvents:UIControlEventValueChanged];
  53. [_batesAddView.pageIndexNumberText addTarget:self action:@selector(changePageStart:) forControlEvents:UIControlEventEditingChanged];
  54. [_batesAddView.pageNumberText addTarget:self action:@selector(changeText:) forControlEvents:UIControlEventEditingChanged];
  55. [_batesAddView.fontNameText addTarget:self action:@selector(changeFontname:) forControlEvents:UIControlEventEditingChanged];
  56. }
  57. - (void)doneBatesClick:(UIBarButtonItem *)btn {
  58. NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:self.modelBatesData,@"batesModel", nil];
  59. NSNotification *notification = [NSNotification notificationWithName:@"getAddBatesModel" object:nil userInfo:dict];
  60. [[NSNotificationCenter defaultCenter] postNotification:notification];
  61. [self.navigationController popViewControllerAnimated:YES];
  62. }
  63. - (void)cancelClick:(UIBarButtonItem *)btn {
  64. [self.navigationController popViewControllerAnimated:YES];
  65. }
  66. - (void)changeText:(UITextField *)text {
  67. self.showLabel.text = text.text;
  68. self.modelBatesData.fontText = text.text;
  69. }
  70. - (void)changePageStart:(UITextField *)text {
  71. int start = [text.text intValue];
  72. self.modelBatesData.pageStart = [NSString stringWithFormat:@"%d",start - 1];
  73. }
  74. - (void)changeFontname:(UITextField *)fontName {
  75. self.showLabel.font = [UIFont fontWithName:fontName.text size:5];
  76. self.modelBatesData.fontName = fontName.text;
  77. self.modelBatesData.fontSize = 15;
  78. }
  79. //slider select color
  80. - (void)sliderChange:(UISlider *)slider {
  81. switch ((int)slider.value/10) {
  82. case 0:
  83. self.showLabel.textColor = [UIColor redColor];
  84. self.modelBatesData.fontColor = [UIColor redColor];
  85. break;
  86. case 1:
  87. self.showLabel.textColor = [UIColor orangeColor];
  88. self.modelBatesData.fontColor = [UIColor orangeColor];
  89. break;
  90. case 2:
  91. self.showLabel.textColor = [UIColor colorWithRed:239.0/255 green:140.0/255 blue:133.0/255 alpha:1];
  92. self.modelBatesData.fontColor = [UIColor colorWithRed:239.0/255 green:140.0/255 blue:133.0/255 alpha:1];
  93. break;
  94. case 3:
  95. self.showLabel.textColor = [UIColor yellowColor];
  96. self.modelBatesData.fontColor = [UIColor yellowColor];
  97. break;
  98. case 4:
  99. self.showLabel.textColor = [UIColor greenColor];
  100. self.modelBatesData.fontColor = [UIColor greenColor];
  101. break;
  102. case 5:
  103. self.showLabel.textColor = [UIColor blueColor];
  104. self.modelBatesData.fontColor = [UIColor blueColor];
  105. break;
  106. case 6:
  107. self.showLabel.textColor = [UIColor purpleColor];
  108. self.modelBatesData.fontColor = [UIColor purpleColor];
  109. break;
  110. case 7:
  111. self.showLabel.textColor = [UIColor colorWithRed:235.0/255 green:61.0/255 blue:133.0/255 alpha:1];
  112. self.modelBatesData.fontColor = [UIColor colorWithRed:235.0/255 green:61.0/255 blue:133.0/255 alpha:1];
  113. break;
  114. case 8:
  115. self.showLabel.textColor = [UIColor blackColor];
  116. self.modelBatesData.fontColor = [UIColor blackColor];
  117. break;
  118. default:
  119. break;
  120. }
  121. }
  122. //select headerfooter
  123. - (void)changeLocation:(UISegmentedControl *)sender {
  124. if (sender.selectedSegmentIndex == 0) {
  125. _position.location = kHeader;
  126. } else {
  127. _position.location = kFooter;
  128. }
  129. [self showPages];
  130. }
  131. //select aligment
  132. - (void)changeAligbment:(UISegmentedControl *)sender {
  133. if (sender.selectedSegmentIndex == 0) {
  134. _position.aligment = kLeft;
  135. } else if (sender.selectedSegmentIndex == 1) {
  136. _position.aligment = kCenter;
  137. } else {
  138. _position.aligment = kRinght;
  139. }
  140. [self showPages];
  141. }
  142. //show headerfooter and aligment
  143. - (void)showPages {
  144. if (_showLabel == nil) {
  145. _showLabel = [[UILabel alloc] init];
  146. }
  147. [_showLabel setText:@"0016"];
  148. _showLabel.font = [UIFont systemFontOfSize:5];
  149. [self.imageView addSubview:self.showLabel];
  150. switch (self.position.location) {
  151. case kHeader:
  152. if (self.position.aligment == kLeft) {
  153. [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  154. make.top.equalTo(_imageView.mas_top).offset(1);
  155. make.left.equalTo(self.imageView.mas_left).offset(1);
  156. make.height.mas_equalTo(5);
  157. make.width.mas_equalTo(20);
  158. }];
  159. self.modelBatesData.fontPosition = 0;
  160. } else if (self.position.aligment == kCenter) {
  161. [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  162. make.top.equalTo(_imageView.mas_top).offset(1);
  163. make.left.equalTo(self.imageView.mas_left).offset(self.size.width / 6);
  164. make.height.mas_equalTo(5);
  165. make.width.mas_equalTo(20);
  166. }];
  167. self.modelBatesData.fontPosition = 1;
  168. } else {
  169. [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  170. make.top.equalTo(self.imageView.mas_top).offset(0.5);
  171. make.left.equalTo(self.imageView.mas_left).offset(self.size.width / 3 - 12);
  172. make.height.mas_equalTo(5);
  173. make.width.mas_equalTo(20);
  174. }];
  175. self.modelBatesData.fontPosition = 2;
  176. }
  177. break;
  178. case kFooter:
  179. if (self.position.aligment == kLeft) {
  180. [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  181. make.top.equalTo(self.imageView.mas_top).offset(self.size.height / 3 - 12);
  182. make.left.equalTo(self.imageView.mas_left).offset(0.5);
  183. make.height.mas_equalTo(5);
  184. make.width.mas_equalTo(20);
  185. }];
  186. self.modelBatesData.fontPosition = 3;
  187. } else if (self.position.aligment == kCenter) {
  188. [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  189. make.top.equalTo(self.imageView.mas_top).offset(self.size.height / 3 - 12);
  190. make.left.equalTo(self.imageView.mas_left).offset(self.size.width/6);
  191. make.height.mas_equalTo(5);
  192. make.width.mas_equalTo(20);
  193. }];
  194. self.modelBatesData.fontPosition = 4;
  195. } else {
  196. [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  197. make.top.equalTo(self.imageView.mas_top).offset(self.size.height / 3 - 12);
  198. make.left.equalTo(self.imageView.mas_left).offset(self.size.width / 3 - 12);
  199. make.height.mas_equalTo(5);
  200. make.width.mas_equalTo(20);
  201. }];
  202. self.modelBatesData.fontPosition = 5;
  203. }
  204. break;
  205. default:
  206. break;
  207. }
  208. }
  209. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  210. if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
  211. [_imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
  212. make.top.equalTo(self.view.mas_top).offset((393/2)-(self.size.height/6));
  213. make.left.equalTo(self.view.mas_left).offset((393/2)-(self.size.width/6));
  214. make.width.mas_equalTo(self.size.width/3);
  215. make.height.mas_equalTo(self.size.height/3);
  216. }];
  217. //add view
  218. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  219. make.top.equalTo(self.view.mas_top).offset(15);
  220. make.left.equalTo(self.view.mas_left).offset(self.view.frame.size.width / 2 + 200);
  221. make.width.mas_equalTo(393);
  222. make.height.mas_equalTo(self.view.frame.size.height - 20);
  223. }];
  224. } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
  225. [_imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
  226. make.top.equalTo(self.view.mas_top).offset(125);
  227. make.left.equalTo(self.view.mas_left).offset((393 / 2)-(self.size.width / 6));
  228. make.width.mas_equalTo(self.size.width / 3);
  229. make.height.mas_equalTo(self.size.height / 3);
  230. }];
  231. //add view
  232. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  233. make.top.equalTo(self.imageView.mas_bottom).offset(60);
  234. make.left.equalTo(self.view.mas_left);
  235. make.width.mas_equalTo(self.view.frame.size.width);
  236. make.height.mas_equalTo(self.view.frame.size.height);
  237. }];
  238. }
  239. }
  240. @end