CPDFTextView.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 KSCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
  10. #define KSCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
  11. #define KBUTTON_WIDTH 28
  12. #define KBUTTON_HEIGHT 28
  13. @implementation CPDFTextView
  14. - (instancetype)initWithFrame:(CGRect)frame {
  15. if (self = [super initWithFrame:frame]) {
  16. [self createView];
  17. [self assignData];
  18. }
  19. return self;
  20. }
  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. _verticalField = [[UITextField alloc] init];
  35. _verticalField.borderStyle = UITextBorderStyleRoundedRect;
  36. _verticalLabel = [[UILabel alloc] init];
  37. _horizontalField = [[UITextField alloc] init];
  38. _horizontalField.borderStyle = UITextBorderStyleRoundedRect;
  39. _horizontalLabel = [[UILabel alloc] init];
  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 setBackgroundColor:[UIColor whiteColor]];
  58. }
  59. - (void)createFrame {
  60. // y -- 40 height -- 30
  61. _opacitySlider.frame = CGRectMake(90, 40, KSCREEN_WIDTH - 100, 30);
  62. _textScaleSlider.frame = CGRectMake(90, 80, KSCREEN_WIDTH - 100, 30);
  63. _tileSwitch.frame = CGRectMake(100, 160, 10, 10);
  64. _rangeLabel.frame = CGRectMake(10, 120, 100, 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. _verticalLabel.frame = CGRectMake(270, 160, 20, 30);
  69. _verticalField.frame = CGRectMake(295, 160, 80, 30);
  70. _horizontalLabel.frame = CGRectMake(165, 160, 20, 30);
  71. _horizontalField.frame = CGRectMake(185, 160, 80, 30);
  72. NSInteger offset = 10;
  73. for (NSInteger i = 0; i < _colorArray.count; i++) {
  74. [[self colorArray][i] setFrame:CGRectMake(offset, 5, KBUTTON_WIDTH, KBUTTON_HEIGHT)];
  75. offset += 50;
  76. [[[self colorArray][i] layer] setCornerRadius:KBUTTON_WIDTH / 2];
  77. [[[self colorArray][i] layer] setMasksToBounds:YES];
  78. }
  79. [_colorArray[0] setBackgroundColor:[UIColor redColor]];
  80. [_colorArray[1] setBackgroundColor:[UIColor orangeColor]];
  81. [_colorArray[2] setBackgroundColor:[UIColor yellowColor]];
  82. [_colorArray[3] setBackgroundColor:[UIColor greenColor]];
  83. [_colorArray[4] setBackgroundColor:[UIColor blueColor]];
  84. [_colorArray[5] setBackgroundColor:[UIColor brownColor]];
  85. [_colorArray[6] setBackgroundColor:[UIColor purpleColor]];
  86. [_colorArray[7] setBackgroundColor:[UIColor grayColor]];
  87. }
  88. //- (void)addConstraint {
  89. // [self.opacityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  90. // make.left.equalTo(self).offset(10);
  91. // make.top.equalTo(self).offset(40);
  92. // make.right.equalTo(self.mas_right).offset(-10);
  93. // }];
  94. // [self.opacitySlider mas_makeConstraints:^(MASConstraintMaker *make) {
  95. // make.left.equalTo(self.mas_left).offset(90);
  96. // make.top.equalTo(self.mas_top).offset(40);
  97. // make.width.equalTo(@(KSCREEN_WIDTH - 100));
  98. // make.height.equalTo(@30);
  99. // }];
  100. //}
  101. - (void)assignData {
  102. _rangeLabel.text = @"Page Range";
  103. _tileLabel.text = @"Full Screen";
  104. _textLabel.text = @"Font Size";
  105. _opacityLabel.text = @"Opacity";
  106. _verticalLabel.text = @"Y:";
  107. _horizontalLabel.text = @"X:";
  108. }
  109. @end