CPDFBackgroundSettingView.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // CPDFBackgroundSettingView.m
  3. // PDFViewer
  4. //
  5. // Created by kdanmobile_2 on 2023/1/2.
  6. //
  7. #import "CPDFBackgroundSettingView.h"
  8. #import "Masonry.h"
  9. @implementation CPDFBackgroundSettingView
  10. - (instancetype)initWithFrame:(CGRect)frame {
  11. self = [super initWithFrame:frame];
  12. if (self) {
  13. _opacitySlider = [[UISlider alloc] init];
  14. _scaleSlider = [[UISlider alloc] init];
  15. _rotationSlider = [[UISlider alloc] init];
  16. [self addSubview:_opacitySlider];
  17. [self addSubview:_scaleSlider];
  18. [self addSubview:_rotationSlider];
  19. _rotationlabel = [[UILabel alloc] init];
  20. _rangeLabel = [[UILabel alloc] init];
  21. _textLabel = [[UILabel alloc] init];
  22. _opacityLabel = [[UILabel alloc] init];
  23. _titleLabel = [[UILabel alloc] init];
  24. [self addSubview:_textLabel];
  25. [self addSubview:_opacityLabel];
  26. [self addSubview:_rangeLabel];
  27. [self addSubview:_rotationlabel];
  28. [self addSubview:_titleLabel];
  29. _verticalField = [[UITextField alloc] init];
  30. _verticalField.borderStyle = UITextBorderStyleRoundedRect;
  31. _verticalLabel = [[UILabel alloc] init];
  32. _horizontalField = [[UITextField alloc] init];
  33. _horizontalField.borderStyle = UITextBorderStyleRoundedRect;
  34. _horizontalLabel = [[UILabel alloc] init];
  35. _pageBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  36. [self addSubview:_verticalLabel];
  37. [self addSubview:_verticalField];
  38. [self addSubview:_horizontalField];
  39. [self addSubview:_horizontalLabel];
  40. [self addSubview:_pageBtn];
  41. _doneBtn = [[UIButton alloc] init];
  42. _cancelBtn = [[UIButton alloc] init];
  43. [self addSubview:_doneBtn];
  44. [self addSubview:_cancelBtn];
  45. self.backgroundColor = [UIColor systemGray6Color];
  46. }
  47. return self;
  48. }
  49. - (void)drawRect:(CGRect)rect {
  50. _titleLabel.frame = CGRectMake(5, 5, 180, 50);
  51. _rangeLabel.frame = CGRectMake(5, 165, 150, 30);
  52. _textLabel.frame = CGRectMake(5, 95, 90, 30);
  53. _opacityLabel.frame = CGRectMake(5, 60, 90, 30);
  54. _rotationlabel.frame = CGRectMake(5, 130, 90, 30);
  55. [self addConstraint];
  56. [self assignData];
  57. }
  58. - (void)addConstraint {
  59. [_verticalField mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.right.equalTo(self.mas_right).offset(-15);
  61. make.top.equalTo(self.pageBtn.mas_bottom).offset(10);
  62. make.width.equalTo(@80);
  63. make.height.equalTo(@30);
  64. }];
  65. [_verticalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.right.equalTo(self.mas_right).offset(-95);
  67. make.top.equalTo(self.pageBtn.mas_bottom).offset(10);
  68. make.width.equalTo(@20);
  69. make.height.equalTo(@30);
  70. }];
  71. [_horizontalField mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.left.equalTo(self.mas_left).offset(25);
  73. make.top.equalTo(self.pageBtn.mas_bottom).offset(10);
  74. make.width.equalTo(@80);
  75. make.height.equalTo(@30);
  76. }];
  77. [_horizontalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.left.equalTo(self.mas_left).offset(5);
  79. make.top.equalTo(self.pageBtn.mas_bottom).offset(10);
  80. make.width.equalTo(@20);
  81. make.height.equalTo(@30);
  82. }];
  83. [_scaleSlider mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.right.equalTo(self.mas_right).offset(-15);
  85. make.left.equalTo(_textLabel.mas_right).offset(0);
  86. make.top.equalTo(self.mas_top).offset(95);
  87. make.height.equalTo(@30);
  88. }];
  89. [_opacitySlider mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.right.equalTo(self.mas_right).offset(-15);
  91. make.left.equalTo(_opacityLabel.mas_right).offset(0);
  92. make.top.equalTo(self.mas_top).offset(60);
  93. make.height.equalTo(@30);
  94. }];
  95. [_rotationSlider mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.right.equalTo(self.mas_right).offset(-15);
  97. make.left.equalTo(_rotationlabel.mas_right).offset(0);
  98. make.top.equalTo(_scaleSlider.mas_bottom).offset(5);
  99. }];
  100. [_pageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.right.equalTo(self.mas_right).offset(-15);
  102. make.top.equalTo(self.rotationSlider.mas_bottom).offset(5);
  103. make.left.equalTo(_rangeLabel.mas_right);
  104. make.height.equalTo(@35);
  105. }];
  106. [_doneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.right.equalTo(self.mas_right).offset(-15);
  108. make.top.equalTo(_horizontalField.mas_bottom).offset(25);
  109. make.height.mas_equalTo(30);
  110. make.width.mas_equalTo(80);
  111. }];
  112. [_cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.right.equalTo(self.mas_right).offset(-110);
  114. make.top.equalTo(_horizontalField.mas_bottom).offset(25);
  115. make.height.mas_equalTo(30);
  116. make.width.mas_equalTo(80);
  117. }];
  118. }
  119. - (void)assignData {
  120. _rangeLabel.text = @"Page Range";
  121. _rangeLabel.font = [UIFont systemFontOfSize:15];
  122. _titleLabel.text = @"Background Edit";
  123. _rotationlabel.text = @"Rotation";
  124. _textLabel.text = @"Scale";
  125. _opacityLabel.text = @"Opacity";
  126. _verticalLabel.text = @"Y:";
  127. _horizontalLabel.text = @"X:";
  128. _scaleSlider.minimumValue = 0.2;
  129. _scaleSlider.maximumValue = 1;
  130. _scaleSlider.value = 1;
  131. _rotationSlider.minimumValue = 0;
  132. _rotationSlider.maximumValue = M_PI;
  133. [_pageBtn setTitle:@"Page Range" forState:UIControlStateNormal];
  134. [_doneBtn setTitle:@"Done" forState:UIControlStateNormal];
  135. [_doneBtn setTitleColor:UIColor.systemBlueColor forState:UIControlStateNormal];
  136. [_cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal];
  137. [_cancelBtn setTitleColor:UIColor.systemBlueColor forState:UIControlStateNormal];
  138. }
  139. @end