PDFWatermarkTextView.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // CPDFTextView.m
  3. // PDFViewer
  4. //
  5. // Created by kdan on 2022/11/16.
  6. //
  7. #import "PDFWatermarkTextView.h"
  8. #import "Masonry.h"
  9. #define KBUTTON_WIDTH 28
  10. #define KBUTTON_HEIGHT 28
  11. @implementation PDFWatermarkTextView
  12. - (instancetype)initWithFrame:(CGRect)frame {
  13. if (self = [super initWithFrame:frame]) {
  14. [self createView];
  15. [self assignData];
  16. self.backgroundColor = [UIColor whiteColor];
  17. }
  18. return self;
  19. }
  20. #pragma mark - Layout
  21. - (void)layoutSubviews {
  22. [super layoutSubviews];
  23. [self createFrame];
  24. [self addConstraint];
  25. }
  26. - (void)createView {
  27. _opacitySlider = [[UISlider alloc] init];
  28. _textScaleSlider = [[UISlider alloc] init];
  29. _tileSwitch = [[UISwitch alloc] init];
  30. _rangeLabel = [[UILabel alloc] init];
  31. _tileLabel = [[UILabel alloc] init];
  32. _textLabel = [[UILabel alloc] init];
  33. _opacityLabel = [[UILabel alloc] init];
  34. _colorLabel = [[UILabel alloc] init];
  35. _verticalField = [[UITextField alloc] init];
  36. _verticalField.borderStyle = UITextBorderStyleRoundedRect;
  37. _verticalLabel = [[UILabel alloc] init];
  38. _horizontalField = [[UITextField alloc] init];
  39. _horizontalField.borderStyle = UITextBorderStyleRoundedRect;
  40. _horizontalLabel = [[UILabel alloc] init];
  41. _pageBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  42. _colorArray = [NSMutableArray array];
  43. for (NSInteger i = 0; i < 8; ++i) {
  44. _colorBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  45. [_colorArray addObject:_colorBtn];
  46. [self addSubview:_colorBtn];
  47. }
  48. [self addSubview:_opacitySlider];
  49. [self addSubview:_textLabel];
  50. [self addSubview:_opacityLabel];
  51. [self addSubview:_textScaleSlider];
  52. [self addSubview:_tileSwitch];
  53. [self addSubview:_rangeLabel];
  54. [self addSubview:_tileLabel];
  55. [self addSubview:_verticalLabel];
  56. [self addSubview:_verticalField];
  57. [self addSubview:_horizontalField];
  58. [self addSubview:_horizontalLabel];
  59. [self addSubview:_colorLabel];
  60. [self addSubview:_pageBtn];
  61. }
  62. - (void)createFrame {
  63. // y -- 40 height -- 30
  64. _tileSwitch.frame = CGRectMake(100, 160, 10, 10);
  65. _rangeLabel.frame = CGRectMake(10, 120, 180, 30);
  66. _tileLabel.frame = CGRectMake(10, 160, 100, 30);
  67. _textLabel.frame = CGRectMake(10, 80, 90, 30);
  68. _opacityLabel.frame = CGRectMake(10, 40, 90, 30);
  69. _colorLabel.frame = CGRectMake(10, 5, 50, 30);
  70. for (NSInteger i = 0; i < _colorArray.count; i++) {
  71. [[[self colorArray][i] layer] setCornerRadius:KBUTTON_WIDTH / 2];
  72. [[[self colorArray][i] layer] setMasksToBounds:YES];
  73. }
  74. [_colorArray[0] setBackgroundColor:[UIColor redColor]];
  75. [_colorArray[1] setBackgroundColor:[UIColor orangeColor]];
  76. [_colorArray[2] setBackgroundColor:[UIColor yellowColor]];
  77. [_colorArray[3] setBackgroundColor:[UIColor greenColor]];
  78. [_colorArray[4] setBackgroundColor:[UIColor blueColor]];
  79. [_colorArray[5] setBackgroundColor:[UIColor brownColor]];
  80. [_colorArray[6] setBackgroundColor:[UIColor purpleColor]];
  81. [_colorArray[7] setBackgroundColor:[UIColor grayColor]];
  82. _pageBtn.layer.borderWidth = 1.0;
  83. _pageBtn.layer.borderColor = UIColor.grayColor.CGColor;
  84. [_pageBtn setTitle:@"Page Range" forState:UIControlStateNormal];
  85. [_pageBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
  86. _pageBtn.layer.cornerRadius = 7;
  87. }
  88. - (void)addConstraint {
  89. [_verticalField mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.right.equalTo(self.mas_right).offset(-15);
  91. make.top.equalTo(self.pageBtn.mas_bottom).offset(10);
  92. make.width.equalTo(@80);
  93. make.height.equalTo(@30);
  94. }];
  95. [_verticalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.right.equalTo(self.mas_right).offset(-95);
  97. make.top.equalTo(self.pageBtn.mas_bottom).offset(10);
  98. make.width.equalTo(@20);
  99. make.height.equalTo(@30);
  100. }];
  101. [_horizontalField mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.right.equalTo(self.mas_right).offset(-115);
  103. make.top.equalTo(self.pageBtn.mas_bottom).offset(10);
  104. make.width.equalTo(@80);
  105. make.height.equalTo(@30);
  106. }];
  107. [_horizontalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.right.equalTo(self.mas_right).offset(-195);
  109. make.top.equalTo(self.pageBtn.mas_bottom).offset(10);
  110. make.width.equalTo(@20);
  111. make.height.equalTo(@30);
  112. }];
  113. [_textScaleSlider mas_makeConstraints:^(MASConstraintMaker *make) {
  114. make.right.equalTo(self.mas_right).offset(-15);
  115. make.left.equalTo(_textLabel.mas_right).offset(0);
  116. make.top.equalTo(self.mas_top).offset(80);
  117. make.height.equalTo(@30);
  118. }];
  119. [_opacitySlider mas_makeConstraints:^(MASConstraintMaker *make) {
  120. make.right.equalTo(self.mas_right).offset(-15);
  121. make.left.equalTo(_opacityLabel.mas_right).offset(0);
  122. make.top.equalTo(self.mas_top).offset(40);
  123. make.height.equalTo(@30);
  124. }];
  125. NSInteger offset = 10;
  126. for (NSInteger i = 0; i < _colorArray.count; ++i) {
  127. [_colorArray[i] mas_makeConstraints:^(MASConstraintMaker *make) {
  128. make.right.equalTo(self.mas_right).offset( - offset);
  129. make.top.equalTo(self.mas_top).offset(5);
  130. make.width.equalTo(@KBUTTON_WIDTH);
  131. make.height.equalTo(@KBUTTON_HEIGHT);
  132. }];
  133. offset += 40;
  134. }
  135. [_pageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  136. make.right.equalTo(self.mas_right).offset(-15);
  137. make.top.equalTo(self.mas_top).offset(115);
  138. make.left.equalTo(_horizontalField.mas_left);
  139. make.height.equalTo(@35);
  140. }];
  141. }
  142. - (void)assignData {
  143. _rangeLabel.text = NSLocalizedString(@"Page Range", nil);
  144. _tileLabel.text = NSLocalizedString(@"Full Screen", nil);
  145. _textLabel.text = NSLocalizedString(@"Font Size", nil);
  146. _opacityLabel.text = NSLocalizedString(@"Opacity", nil);
  147. _verticalLabel.text = @"Y:";
  148. _horizontalLabel.text = @"X:";
  149. _colorLabel.text = NSLocalizedString(@"Color", nil);
  150. }
  151. @end