CPDFHeaderFooterAddView.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // HeaderFooterAddView.m
  3. // PDFViewer
  4. //
  5. // Created by kdanmobile_2 on 2022/11/16.
  6. //
  7. #import "CPDFHeaderFooterAddView.h"
  8. @implementation CPDFHeaderFooterAddView
  9. - (instancetype)initWithFrame:(CGRect)frame {
  10. self = [super initWithFrame:frame];
  11. CGFloat height = self.bounds.size.height / 15 - 35;
  12. CGFloat width = self.bounds.size.width / 4 - 10;
  13. CGFloat offsetx = 3.5;
  14. if (self) {
  15. //Page number location
  16. _localLabel = [[UILabel alloc] initWithFrame:CGRectMake(offsetx, offsetx, width * 2, height)];
  17. [_localLabel setText:@"Page number position"];
  18. _localLabel.font = [UIFont boldSystemFontOfSize:12];
  19. NSArray *arraySegmmentL = [NSArray arrayWithObjects:@"Header",@"Footer", nil];
  20. _localSegment = [[UISegmentedControl alloc] initWithItems:arraySegmmentL];
  21. _localSegment.frame = CGRectMake(4 * offsetx, height + 2 * offsetx, self.bounds.size.width - 8 * offsetx, height * 2);
  22. [self addSubview:_localLabel];
  23. [self addSubview:_localSegment];
  24. //alignment
  25. _alignmentLabel = [[UILabel alloc] initWithFrame:CGRectMake(3.5, 3 * height + 3 * offsetx, width, height)];
  26. [_alignmentLabel setText:@"alignment"];
  27. _alignmentLabel.font = [UIFont boldSystemFontOfSize:12];
  28. NSArray *arraySegmmentA = [NSArray arrayWithObjects:@"Left",@"Center",@"Right", nil];
  29. _aligbmentSegment = [[UISegmentedControl alloc] initWithItems:arraySegmmentA];
  30. _aligbmentSegment.frame = CGRectMake(4 * offsetx, 4 * height + 4 * offsetx, self.bounds.size.width - 8 * offsetx, height * 2);
  31. [self addSubview:_alignmentLabel];
  32. [self addSubview:_aligbmentSegment];
  33. //font color
  34. _colorLabel = [[UILabel alloc] initWithFrame:CGRectMake(3.5, 6 * height + 5 * offsetx, width, height)];
  35. [_colorLabel setText:@"Font Color"];
  36. _colorLabel.font = [UIFont boldSystemFontOfSize:12];
  37. _colerImage = [[UIImageView alloc] initWithFrame:CGRectMake(4 * offsetx,7 * height + 6 * offsetx , self.bounds.size.width, 2*height)];
  38. _colerImage.image = [UIImage imageNamed:@"text_color_bar"];
  39. _colorSlider = [[UISlider alloc] initWithFrame:CGRectMake(4 * offsetx,9 * height + 7 * offsetx , self.bounds.size.width - 8 * offsetx, 2 * height)];
  40. _colorSlider.minimumValue = 0;
  41. _colorSlider.maximumValue = 90;
  42. _colorSlider.value = 5;
  43. [self addSubview:_colorLabel];
  44. [self addSubview:_colorSlider];
  45. [self addSubview:_colerImage];
  46. //page number
  47. _pageNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(3.5, 11 * height + 8 * offsetx, width + offsetx, height * 2)];
  48. [_pageNumberLabel setText:@"Page Text"];
  49. _pageNumberLabel.font = [UIFont boldSystemFontOfSize:14];
  50. NSArray *str = [[NSArray alloc] initWithObjects:@"1",@"第1页", nil];
  51. _dropdownView = [[CPDFDropDownView alloc] initWithFrame:CGRectMake(2 * offsetx + width, 11 * height + 8 * offsetx, width - offsetx, height * 2) WithString:str];
  52. [self addSubview:_dropdownView];
  53. [self addSubview:_pageNumberLabel];
  54. //font size
  55. _fontSizeLabel = [[UILabel alloc] initWithFrame:CGRectMake(3 * offsetx + width * 2, 11 * height + 8 * offsetx, width, height * 2)];
  56. [_fontSizeLabel setText:@"Font Szie"];
  57. _fontSizeLabel.font = [UIFont boldSystemFontOfSize:14];
  58. _fontSizeText = [[UITextField alloc] initWithFrame:CGRectMake(2 * offsetx + 3 * width, 11 * height + 8 * offsetx, width, height * 2)];
  59. _fontSizeText.borderStyle = UITextBorderStyleRoundedRect;
  60. [self addSubview:_fontSizeLabel];
  61. [self addSubview:_fontSizeText];
  62. //font index
  63. _pageIndexLabel = [[UILabel alloc] initWithFrame:CGRectMake(offsetx, 13 * height + 9 * offsetx, width, height * 2)];
  64. [_pageIndexLabel setText:@"Page Star"];
  65. _pageIndexLabel.font = [UIFont boldSystemFontOfSize:14];
  66. _pageIndexNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(offsetx + width, 13 * height + 10 * offsetx, width, height * 2)];
  67. _pageIndexNumberLabel.backgroundColor = [UIColor whiteColor];
  68. _pageIndexNumberLabel.textColor = [UIColor blackColor];
  69. _pageIndexNumberLabel.textAlignment = NSTextAlignmentCenter;
  70. _pageIndexNumberStepper = [[UIStepper alloc] initWithFrame:CGRectMake(offsetx + width * 2, 13 * height + 11 * offsetx, width, height * 2)];
  71. // The step value is updated in real time as the user interacts
  72. _pageIndexNumberStepper.continuous = YES; // default = YES
  73. // The user continues to press and hold, automatically increasing or decreasing
  74. _pageIndexNumberStepper.autorepeat = YES; // default = YES
  75. // If set to YES, the value loops between min <-> max
  76. _pageIndexNumberStepper.wraps = NO; // default = NO
  77. _pageIndexNumberStepper.minimumValue = 1; // default 0
  78. _pageIndexNumberStepper.maximumValue = 100; // default 100
  79. _pageIndexNumberStepper.stepValue = 1; // default 1
  80. _pageIndexNumberStepper.value = 1;
  81. // 设置 Target-Action
  82. [_pageIndexNumberStepper addTarget:self
  83. action:@selector(stepperValueChanged:)
  84. forControlEvents:UIControlEventValueChanged];
  85. [self addSubview:_pageIndexLabel];
  86. [self addSubview:_pageIndexNumberLabel];
  87. [self addSubview:_pageIndexNumberStepper];
  88. self.backgroundColor = [UIColor whiteColor];
  89. }
  90. return self;
  91. }
  92. - (void)stepperValueChanged:(UIStepper *)pageIndexNumberStepper {
  93. int pageIndex = (int)pageIndexNumberStepper.value;
  94. NSString *value = [NSString stringWithFormat:@"%d",pageIndex];
  95. self.pageIndexLabel.font = [UIFont boldSystemFontOfSize:12.0];
  96. self.pageIndexNumberLabel.text = value;
  97. }
  98. @end