PDFBatesAddViewController.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. //
  2. // BatesAddViewController.m
  3. // PDFViewer
  4. //
  5. // Created by kdanmobile_2 on 2022/11/18.
  6. //
  7. #import "PDFBatesAddViewController.h"
  8. #import "PDFAddViewControllerHeader.h"
  9. @interface PDFBatesAddViewController ()
  10. @property (retain, nonatomic) IBOutlet UILabel *localLabel;
  11. @property (retain, nonatomic) IBOutlet UISegmentedControl *localSegment;
  12. @property (retain, nonatomic) IBOutlet UILabel *alignmentLabel;
  13. @property (retain, nonatomic) IBOutlet UISegmentedControl *aligbmentSegment;
  14. @property (retain, nonatomic) IBOutlet UILabel *colorLabel;
  15. @property (retain, nonatomic) IBOutlet UIImageView *colerImage;
  16. @property (retain, nonatomic) IBOutlet UISlider *colorSlider;
  17. @property (retain, nonatomic) IBOutlet UILabel *pageNumberLabel;
  18. @property (retain, nonatomic) IBOutlet UITextField *pageNumberText;
  19. @property (retain, nonatomic) IBOutlet UILabel *fontNameLabel;
  20. @property (retain, nonatomic) IBOutlet UITextField *fontNameText;
  21. @property (retain, nonatomic) IBOutlet UILabel *pageIndexLabel;
  22. @property (retain, nonatomic) IBOutlet UITextField *pageIndexNumberText;
  23. @property (retain, nonatomic) IBOutlet UIImageView *preImaview;
  24. @property (retain, nonatomic) IBOutlet UILabel *preLabel1;
  25. @property (retain, nonatomic) IBOutlet UILabel *preLabel2;
  26. @property (retain, nonatomic) IBOutlet UILabel *preLabel3;
  27. @property (retain, nonatomic) IBOutlet UILabel *preLabel4;
  28. @property (retain, nonatomic) IBOutlet UILabel *preLabel5;
  29. @property (retain, nonatomic) IBOutlet UILabel *preLabel;
  30. @property (retain, nonatomic) IBOutlet UILabel *titleView;
  31. @property (retain, nonatomic) IBOutlet UIButton *okBtn;
  32. @property (retain, nonatomic) IBOutlet UITableView *tableView;
  33. @property (retain, nonatomic) IBOutlet UIView *pageFormatView;
  34. @property (retain, nonatomic) IBOutlet UIView *batesAddView;
  35. //@property (nonatomic,strong) PDFHeaderFooterTextTableView *fontName;
  36. @property (nonatomic,strong) NSMutableArray *dataArray;
  37. //@property (nonatomic,strong) PDFBatesAddView *batesAddView;
  38. @end
  39. @implementation PDFBatesAddViewController
  40. #pragma mark - UIViewController Methods
  41. - (void)viewDidLoad {
  42. [super viewDidLoad];
  43. // Do any additional setup after loading the view.
  44. [self initHeadView];
  45. [self initButtonView];
  46. }
  47. - (void)viewDidLayoutSubviews {
  48. [super viewDidLayoutSubviews];
  49. [self initBasicEvent];
  50. [self initExtendEvent];
  51. }
  52. - (void)initHeadView {
  53. _preImaview.image = self.image;
  54. CALayer *layer = [_preImaview layer];
  55. layer.borderColor = [[UIColor blackColor] CGColor];
  56. layer.borderWidth = 0.2f;
  57. _preLabel1.hidden = NO;
  58. _preLabel2.hidden = YES;
  59. _preLabel3.hidden = YES;
  60. _preLabel4.hidden = YES;
  61. _preLabel5.hidden = YES;
  62. _preLabel.hidden = YES;
  63. }
  64. - (void)initButtonView {
  65. _tableView.delegate = self;
  66. _tableView.dataSource = self;
  67. [_okBtn setTitle:@" " forState:UIControlStateNormal];
  68. }
  69. #pragma mark - Initializers
  70. - (void)initNavigation {
  71. self.navigationItem.title = NSLocalizedString(@"Add Bates", nil);
  72. self.navigationController.toolbarHidden = YES;
  73. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneBatesClick:)];
  74. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelClick:)];
  75. }
  76. - (void)initModel {
  77. self.modelData = [[PDFHeaderFooterModel alloc] init];
  78. self.modelData.fontName = @"Helvetica";
  79. self.modelData.fontPosition = 0;
  80. self.modelData.fontText = @"#2#1#0#0";
  81. self.modelData.fontColor = [UIColor blackColor];
  82. }
  83. - (void)initBasicEvent {
  84. [_localSegment addTarget:self action:@selector(changeLocation:) forControlEvents:UIControlEventValueChanged];
  85. [_aligbmentSegment addTarget:self action:@selector(changeAligbment:) forControlEvents:UIControlEventValueChanged];
  86. }
  87. - (void)initExtendEvent {
  88. _fontNameText.delegate = self;
  89. }
  90. #pragma mark - Accessors
  91. - (NSArray *)dataArray {
  92. if (!_dataArray) {
  93. _dataArray = [NSMutableArray array];
  94. NSArray *fontNameArray = [[NSArray alloc] initWithObjects:@"Helvetica",@"Arial",@"Arial Rounded MT Bold", @"Arial Unicode MS",@"Courier",nil];
  95. for (int i = 0; i < fontNameArray.count; i++) {
  96. [_dataArray addObject:fontNameArray[i]];
  97. }
  98. }
  99. return _dataArray;
  100. }
  101. #pragma mark - UITextFieldDelegate
  102. - (void)textFieldDidBeginEditing:(UITextField *)textField {
  103. if (_fontNameText == textField) {
  104. _pageFormatView.hidden = NO;
  105. [self.okBtn addTarget:self action:@selector(fontNameOk:) forControlEvents:UIControlEventTouchUpInside];
  106. }
  107. }
  108. - (void)textFieldDidChangeSelection:(UITextField *)textField {
  109. if (_fontNameText == textField) {
  110. _pageFormatView.hidden = NO;
  111. }
  112. }
  113. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  114. [textField resignFirstResponder];
  115. return YES;
  116. }
  117. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  118. if (_pageNumberText == textField) {
  119. return [self validateValue:string];
  120. }
  121. return YES;
  122. }
  123. - (BOOL)validateValue:(NSString *)number {
  124. BOOL res = YES;
  125. NSCharacterSet *numberSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
  126. NSInteger i = 0;
  127. while (i < number.length) {
  128. NSString *str = [number substringWithRange:NSMakeRange(i, 1)];
  129. NSRange range = [str rangeOfCharacterFromSet:numberSet];
  130. if (range.length == 0) {
  131. res = NO;
  132. break;
  133. }
  134. i++;
  135. }
  136. return res;
  137. }
  138. #pragma mark - UITableViewDataSource
  139. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  140. return self.dataArray.count;
  141. }
  142. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  143. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fontName"];
  144. if (cell == nil) {
  145. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"fontName"];
  146. }
  147. cell.textLabel.text = self.dataArray[indexPath.row];
  148. return cell;
  149. }
  150. #pragma mark - UITableViewDelegate
  151. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  152. self.modelData.fontName = self.dataArray[indexPath.row];
  153. self.preLabel1.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
  154. self.preLabel2.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
  155. self.preLabel3.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
  156. self.preLabel4.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
  157. self.preLabel5.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
  158. self.preLabel.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
  159. }
  160. #pragma mark - Actions
  161. // Done button enable
  162. - (void)doneBatesClick:(UIBarButtonItem *)btn {
  163. if ([self.delegate respondsToSelector:@selector(PDFViewPerformChangBates:)]) {
  164. [self.delegate PDFViewPerformChangBates:self.modelData];
  165. }
  166. [self.navigationController popViewControllerAnimated:YES];
  167. }
  168. // Candel button enable
  169. - (void)cancelClick:(UIBarButtonItem *)btn {
  170. [self.navigationController popViewControllerAnimated:YES];
  171. }
  172. - (void)fontNameOk:(UIButton *)okBtn {
  173. self.fontNameText.text = self.modelData.fontName;
  174. _pageFormatView.hidden = YES;
  175. // [_fontName removeFromSuperview];
  176. }
  177. #pragma mark - UI Functions
  178. - (IBAction)colorChange:(UISlider *)sender {
  179. switch ((int)sender.value / 10) {
  180. case 0:
  181. self.preLabel1.textColor = [UIColor redColor];
  182. self.preLabel2.textColor = [UIColor redColor];
  183. self.preLabel3.textColor = [UIColor redColor];
  184. self.preLabel4.textColor = [UIColor redColor];
  185. self.preLabel5.textColor = [UIColor redColor];
  186. self.preLabel.textColor = [UIColor redColor];
  187. self.modelData.fontColor = [UIColor redColor];
  188. break;
  189. case 1:
  190. self.preLabel1.textColor = [UIColor orangeColor];
  191. self.preLabel2.textColor = [UIColor orangeColor];
  192. self.preLabel3.textColor = [UIColor orangeColor];
  193. self.preLabel4.textColor = [UIColor orangeColor];
  194. self.preLabel5.textColor = [UIColor orangeColor];
  195. self.preLabel.textColor = [UIColor orangeColor];
  196. self.modelData.fontColor = [UIColor orangeColor];
  197. break;
  198. case 2:
  199. self.preLabel1.textColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1];
  200. self.preLabel2.textColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1];
  201. self.preLabel3.textColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1];
  202. self.preLabel4.textColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1];
  203. self.preLabel5.textColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1];
  204. self.preLabel.textColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1];
  205. self.modelData.fontColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1];
  206. break;
  207. case 3:
  208. self.preLabel1.textColor = [UIColor yellowColor];
  209. self.preLabel2.textColor = [UIColor yellowColor];
  210. self.preLabel3.textColor = [UIColor yellowColor];
  211. self.preLabel4.textColor = [UIColor yellowColor];
  212. self.preLabel5.textColor = [UIColor yellowColor];
  213. self.preLabel.textColor = [UIColor yellowColor];
  214. self.modelData.fontColor = [UIColor yellowColor];;
  215. break;
  216. case 4:
  217. self.preLabel1.textColor = [UIColor greenColor];
  218. self.preLabel2.textColor = [UIColor greenColor];
  219. self.preLabel3.textColor = [UIColor greenColor];
  220. self.preLabel4.textColor = [UIColor greenColor];
  221. self.preLabel5.textColor = [UIColor greenColor];
  222. self.preLabel.textColor = [UIColor greenColor];
  223. self.modelData.fontColor = [UIColor greenColor];
  224. break;
  225. case 5:
  226. self.preLabel1.textColor = [UIColor blueColor];
  227. self.preLabel2.textColor = [UIColor blueColor];
  228. self.preLabel3.textColor = [UIColor blueColor];
  229. self.preLabel4.textColor = [UIColor blueColor];
  230. self.preLabel5.textColor = [UIColor blueColor];
  231. self.preLabel.textColor = [UIColor blueColor];
  232. self.modelData.fontColor = [UIColor blueColor];
  233. break;
  234. case 6:
  235. self.preLabel1.textColor = [UIColor purpleColor];
  236. self.preLabel2.textColor = [UIColor purpleColor];
  237. self.preLabel3.textColor = [UIColor purpleColor];
  238. self.preLabel4.textColor = [UIColor purpleColor];
  239. self.preLabel5.textColor = [UIColor purpleColor];
  240. self.preLabel.textColor = [UIColor purpleColor];
  241. self.modelData.fontColor = [UIColor purpleColor];
  242. break;
  243. case 7:
  244. self.preLabel1.textColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1];
  245. self.preLabel2.textColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1];
  246. self.preLabel3.textColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1];
  247. self.preLabel4.textColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1];
  248. self.preLabel5.textColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1];
  249. self.preLabel.textColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1];
  250. self.modelData.fontColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1];
  251. break;
  252. case 8:
  253. self.preLabel1.textColor = [UIColor blackColor];
  254. self.preLabel2.textColor = [UIColor blackColor];
  255. self.preLabel3.textColor = [UIColor blackColor];
  256. self.preLabel4.textColor = [UIColor blackColor];
  257. self.preLabel5.textColor = [UIColor blackColor];
  258. self.preLabel.textColor = [UIColor blackColor];
  259. self.modelData.fontColor = [UIColor blackColor];
  260. break;
  261. case 9:
  262. self.preLabel1.textColor = [UIColor whiteColor];
  263. self.preLabel2.textColor = [UIColor whiteColor];
  264. self.preLabel3.textColor = [UIColor whiteColor];
  265. self.preLabel4.textColor = [UIColor whiteColor];
  266. self.preLabel5.textColor = [UIColor whiteColor];
  267. self.preLabel.textColor = [UIColor whiteColor];
  268. self.modelData.fontColor = [UIColor whiteColor];
  269. break;
  270. default:
  271. break;
  272. }
  273. }
  274. - (void)showPages {
  275. switch (self.position.location) {
  276. case PDFHeaderFooterLocationHeader:
  277. if (self.position.aligment == PDFHeaderFooerAligmentLeft) {
  278. _preLabel1.hidden = NO;
  279. _preLabel2.hidden = YES;
  280. _preLabel3.hidden = YES;
  281. _preLabel4.hidden = YES;
  282. _preLabel5.hidden = YES;
  283. _preLabel.hidden = YES;
  284. self.modelData.fontPosition = 0;
  285. } else if (self.position.aligment == PDFHeaderFooerAligmentCenter) {
  286. _preLabel1.hidden = YES;
  287. _preLabel2.hidden = NO;
  288. _preLabel3.hidden = YES;
  289. _preLabel4.hidden = YES;
  290. _preLabel5.hidden = YES;
  291. _preLabel.hidden = YES;
  292. self.modelData.fontPosition = 1;
  293. } else {
  294. _preLabel1.hidden = YES;
  295. _preLabel2.hidden = YES;
  296. _preLabel3.hidden = NO;
  297. _preLabel4.hidden = YES;
  298. _preLabel5.hidden = YES;
  299. _preLabel.hidden = YES;
  300. self.modelData.fontPosition = 2;
  301. }
  302. break;
  303. case PDFHeaderFooterLocationFooter:
  304. if (self.position.aligment == PDFHeaderFooerAligmentLeft) {
  305. _preLabel1.hidden = YES;
  306. _preLabel2.hidden = YES;
  307. _preLabel3.hidden = YES;
  308. _preLabel4.hidden = NO;
  309. _preLabel5.hidden = YES;
  310. _preLabel.hidden = YES;
  311. self.modelData.fontPosition = 3;
  312. } else if (self.position.aligment == PDFHeaderFooerAligmentCenter) {
  313. _preLabel1.hidden = YES;
  314. _preLabel2.hidden = YES;
  315. _preLabel3.hidden = YES;
  316. _preLabel4.hidden = YES;
  317. _preLabel5.hidden = NO;
  318. _preLabel.hidden = YES;
  319. self.modelData.fontPosition = 4;
  320. } else {
  321. _preLabel1.hidden = YES;
  322. _preLabel2.hidden = YES;
  323. _preLabel3.hidden = YES;
  324. _preLabel4.hidden = YES;
  325. _preLabel5.hidden = YES;
  326. _preLabel.hidden = NO;
  327. self.modelData.fontPosition = 5;
  328. }
  329. break;
  330. default:
  331. break;
  332. }
  333. }
  334. // Get page text for bates's model
  335. - (IBAction)changeText:(UITextField *)sender {
  336. NSArray *textArray = [sender.text componentsSeparatedByString:@"#"];
  337. NSString *showText = [[NSString alloc] init];
  338. if (sender.text.length >= 2) {
  339. int i = [textArray[1] intValue];
  340. for (int j = 0; j < i-1; j++) {
  341. NSString *test = showText;
  342. showText = [NSString stringWithFormat:@"%d%@",0,test];
  343. }
  344. }
  345. if (sender.text.length >= 4) {
  346. showText = [NSString stringWithFormat:@"%@%@",showText,textArray[2]];
  347. }
  348. if (sender.text.length >= 6) {
  349. showText = [NSString stringWithFormat:@"%@%@",textArray[3],showText];
  350. }
  351. if (sender.text.length == 8) {
  352. showText = [NSString stringWithFormat:@"%@%@",showText,textArray[4]];
  353. }
  354. self.preLabel1.text = showText;
  355. self.preLabel2.text = showText;
  356. self.preLabel3.text = showText;
  357. self.preLabel4.text = showText;
  358. self.preLabel5.text = showText;
  359. self.preLabel.text = showText;
  360. self.modelData.fontText = sender.text;
  361. }
  362. // Get page text start for bates's model
  363. - (IBAction)changePageStart:(UITextField *)sender {
  364. int start = [sender.text intValue];
  365. self.modelData.pageStart = [NSString stringWithFormat:@"%d",start - 1];
  366. }
  367. - (IBAction)PDFBatesAddViewUp:(UITextField *)sender {
  368. if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown) {
  369. } else {
  370. [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  371. self.batesAddView.center = CGPointMake(self.batesAddView.center.x, self.batesAddView.center.y - 300);
  372. } completion:nil];
  373. }
  374. }
  375. - (IBAction)PDFBatesAddViewDown:(UITextField *)sender {
  376. if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown) {
  377. } else {
  378. [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  379. self.batesAddView.center = CGPointMake(self.batesAddView.center.x, self.batesAddView.center.y + 300);
  380. } completion:nil];
  381. }
  382. }
  383. @end