PDFHeaderFooterAddController.m 17 KB

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