PDFWatermarkTextPreview.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // CPDFTextPreview.m
  3. // PDFViewer
  4. //
  5. // Created by kdan on 2022/11/18.
  6. //
  7. #import "PDFWatermarkTextPreview.h"
  8. #import "Masonry.h"
  9. BOOL gTextPreviewIsFirstLayout = YES;
  10. @implementation PDFWatermarkTextPreview
  11. - (instancetype)initWithFrame:(CGRect)frame
  12. {
  13. if (self = [super initWithFrame:frame]) {
  14. _rotationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  15. [self.documentImageView addSubview:self.preLabel];
  16. [self.preLabel addSubview:_rotationBtn];
  17. self.backgroundColor = [UIColor grayColor];
  18. }
  19. return self;
  20. }
  21. #pragma mark - Drawrect
  22. - (void)drawRect:(CGRect)rect {
  23. [super drawRect:rect];
  24. self.preLabel.layer.borderWidth = 1;
  25. self.preLabel.layer.borderColor = UIColor.blueColor.CGColor;
  26. [self.preLabel sizeToFit];
  27. /*
  28. this have a core was delete:
  29. if (gTextPreviewIsFirstLayout) {
  30. gTextPreviewIsFirstLayout = NO;
  31. }
  32. */
  33. CGRect frame = self.preLabel.frame;
  34. frame.origin = CGPointMake(self.documentImageView.bounds.size.width / 2 - self.preLabel.frame.size.width / 2, self.documentImageView.bounds.size.height / 2 - self.preLabel.frame.size.height / 2);
  35. self.preLabel.frame = frame;
  36. _rotationBtn.layer.cornerRadius = 10;
  37. _rotationBtn.layer.masksToBounds = YES;
  38. _rotationBtn.layer.borderColor = UIColor.blueColor.CGColor;
  39. [_rotationBtn setBackgroundImage:[UIImage imageNamed:@"btn_selected"] forState:UIControlStateNormal];
  40. [_rotationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.top.equalTo(self.preLabel.mas_bottom).offset(-15);
  42. make.width.equalTo(@30);
  43. make.height.equalTo(@30);
  44. make.left.equalTo(self.preLabel.mas_right).offset(-15);
  45. }];
  46. }
  47. @end