PDFWatermarkImageView.m 5.3 KB

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