CPDFImageView.m 5.2 KB

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