CPDFTextView.m 5.9 KB

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