PDFBatesAddView.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // BatesAddView.m
  3. // PDFViewer
  4. //
  5. // Created by kdanmobile_2 on 2022/11/18.
  6. //
  7. #import "PDFBatesAddView.h"
  8. #import "Masonry.h"
  9. @implementation PDFBatesAddView
  10. - (instancetype)initWithFrame:(CGRect)frame {
  11. self = [super initWithFrame:frame];
  12. if (self) {
  13. // Font index
  14. _pageIndexLabel = [[UILabel alloc] init];
  15. _pageIndexNumberText = [[UITextField alloc] init];
  16. [self addSubview:_pageIndexLabel];
  17. [self addSubview:_pageIndexNumberText];
  18. // Font Name
  19. _fontNameLabel = [[UILabel alloc] init];
  20. _fontNameText = [[UITextField alloc] init];
  21. [self addSubview:_fontNameLabel];
  22. [self addSubview:_fontNameText];
  23. // Page number
  24. _pageNumberLabel = [[UILabel alloc] init];
  25. _pageNumberText = [[UITextField alloc] init];
  26. [self addSubview:_pageNumberLabel];
  27. [self addSubview:_pageNumberText];
  28. self.backgroundColor = [UIColor whiteColor];
  29. }
  30. return self;
  31. }
  32. #pragma mark - Layout
  33. - (void)layoutSubviews {
  34. [super layoutSubviews];
  35. CGFloat offsetx = 3.5;
  36. // Font index
  37. [_pageIndexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.top.equalTo(self.colorSlider.mas_bottom).offset(offsetx);
  39. make.left.equalTo(self.mas_left).offset(offsetx);
  40. make.height.mas_equalTo(34);
  41. make.width.mas_equalTo(73);
  42. }];
  43. [_pageIndexNumberText mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.equalTo(self.colorSlider.mas_bottom).offset(offsetx);
  45. make.left.equalTo(_pageIndexLabel.mas_right).offset(offsetx);
  46. make.height.mas_equalTo(34);
  47. make.width.mas_equalTo(93);
  48. }];
  49. // Font Name
  50. [_fontNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.top.equalTo(self.colorSlider.mas_bottom).offset(offsetx);
  52. make.left.equalTo(_pageIndexNumberText.mas_right).offset(offsetx + 20);
  53. make.height.mas_equalTo(34);
  54. make.width.mas_equalTo(73);
  55. }];
  56. [_fontNameText mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.top.equalTo(self.colorSlider.mas_bottom).offset(offsetx);
  58. make.left.equalTo(_fontNameLabel.mas_right).offset(offsetx);
  59. make.height.mas_equalTo(34);
  60. make.width.mas_equalTo(93);
  61. }];
  62. // Page number
  63. [_pageNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.top.equalTo(_pageIndexLabel.mas_bottom).offset(offsetx);
  65. make.left.equalTo(self.mas_left).offset(offsetx);
  66. make.height.mas_equalTo(34);
  67. make.width.mas_equalTo(73);
  68. }];
  69. [_pageNumberText mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.top.equalTo(_pageIndexNumberText.mas_bottom).offset(offsetx+5);
  71. make.left.equalTo(_pageNumberLabel.mas_right).offset(offsetx);
  72. make.height.mas_equalTo(33);
  73. make.width.mas_equalTo(153);
  74. }];
  75. }
  76. #pragma mark - Assignment
  77. - (void)setText {
  78. // Page number location
  79. [self.localLabel setText:NSLocalizedString(@"Page number position", nil)];
  80. self.localLabel.font = [UIFont boldSystemFontOfSize:12];
  81. // Alignment
  82. [self.alignmentLabel setText:NSLocalizedString(@"alignment", nil)];
  83. self.alignmentLabel.font = [UIFont boldSystemFontOfSize:12];
  84. // Font color
  85. [self.colorLabel setText:NSLocalizedString(@"Font Color", nil)];
  86. self.colorLabel.font = [UIFont boldSystemFontOfSize:12];
  87. CALayer *layer = [self.colerImage layer];
  88. layer.borderColor = [[UIColor blackColor] CGColor];
  89. layer.borderWidth = 0.5f;
  90. self.colerImage.image = [UIImage imageNamed:@"text_color_bar"];
  91. self.colorSlider.minimumValue = 0;
  92. self.colorSlider.maximumValue = 100;
  93. self.colorSlider.value = 5;
  94. // Font index
  95. [_pageIndexLabel setText:NSLocalizedString(@"Start Page", nil)];
  96. _pageIndexLabel.font = [UIFont boldSystemFontOfSize:12];
  97. _pageIndexNumberText.delegate = self;
  98. _pageIndexNumberText.borderStyle = UITextBorderStyleRoundedRect;
  99. _pageIndexNumberText.placeholder = @"1";
  100. // Font Name
  101. [_fontNameLabel setText:NSLocalizedString(@"Font Name", nil)];
  102. _fontNameLabel.font = [UIFont boldSystemFontOfSize:12];
  103. _fontNameText.inputView = [[UIView alloc] initWithFrame:CGRectZero];
  104. _fontNameText.inputAccessoryView = [[UIView alloc] initWithFrame:CGRectZero];
  105. _fontNameText.adjustsFontSizeToFitWidth = YES;
  106. _fontNameText.minimumFontSize = 6;
  107. _fontNameText.borderStyle = UITextBorderStyleRoundedRect;
  108. _fontNameText.tintColor = [UIColor clearColor];
  109. _fontNameText.placeholder = @"Helvetica";
  110. _fontNameText.keyboardType = UIKeyboardTypeDefault;
  111. _fontNameText.delegate = self;
  112. // Page number
  113. [_pageNumberLabel setText:NSLocalizedString(@"Page Text", nil)];
  114. _pageNumberLabel.font = [UIFont boldSystemFontOfSize:14];
  115. _pageNumberText.delegate = self;
  116. _pageNumberText.borderStyle = UITextBorderStyleRoundedRect;
  117. _pageNumberText.placeholder = @"#2#1#0#0";
  118. }
  119. #pragma mark - UITextFieldDelegate
  120. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  121. [textField resignFirstResponder];
  122. return YES;
  123. }
  124. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  125. if (_pageIndexNumberText == textField) {
  126. return [self validateValue:string];
  127. }
  128. return YES;
  129. }
  130. - (BOOL)validateValue:(NSString *)number {
  131. BOOL res = YES;
  132. NSCharacterSet *numberSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
  133. NSInteger i = 0;
  134. while (i < number.length) {
  135. NSString *str = [number substringWithRange:NSMakeRange(i, 1)];
  136. NSRange range = [str rangeOfCharacterFromSet:numberSet];
  137. if (range.length == 0) {
  138. res = NO;
  139. break;
  140. }
  141. i++;
  142. }
  143. return res;
  144. }
  145. @end