CPDFTextPreview.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // CPDFTextPreview.m
  3. // PDFViewer
  4. //
  5. // Created by kdan on 2022/11/18.
  6. //
  7. #import "CPDFTextPreview.h"
  8. #import "Masonry.h"
  9. @implementation CPDFTextPreview
  10. - (instancetype)initWithFrame:(CGRect)frame
  11. {
  12. if (self = [super initWithFrame:frame]) {
  13. _watermarkLabel = [[UILabel alloc] init];
  14. _rotationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  15. _documentView = [[UIImageView alloc] init];
  16. [self addSubview:_documentView];
  17. [_documentView addSubview:_watermarkLabel];
  18. [_documentView addSubview:_rotationBtn];
  19. }
  20. return self;
  21. }
  22. - (void)layoutSubviews {
  23. [super layoutSubviews];
  24. _watermarkLabel.layer.borderWidth = 2;
  25. _watermarkLabel.layer.borderColor = UIColor.blackColor.CGColor;
  26. _watermarkLabel.text = @"Watermark";
  27. _watermarkLabel.textColor = UIColor.redColor;
  28. _watermarkLabel.font = [UIFont systemFontOfSize:24];
  29. [_watermarkLabel sizeToFit];
  30. CGRect frame = _watermarkLabel.frame;
  31. frame.origin = CGPointMake(self.bounds.size.width / 2 - _watermarkLabel.frame.size.width / 2, self.bounds.size.height / 2 - _watermarkLabel.frame.size.height / 2);
  32. _watermarkLabel.frame = frame;
  33. _rotationBtn.layer.cornerRadius = 10;
  34. _rotationBtn.layer.masksToBounds = YES;
  35. _rotationBtn.layer.borderColor = UIColor.blueColor.CGColor;
  36. [_rotationBtn setBackgroundImage:[UIImage imageNamed:@"btn_selected"] forState:UIControlStateNormal];
  37. // [_rotationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  38. // make.top.equalTo(self.watermarkLabel).offset(self.watermarkLabel.frame.size.height - 10);
  39. // make.bottom.equalTo(self.watermarkLabel).offset(10);
  40. // make.right.equalTo(self.watermarkLabel).offset(20);
  41. // make.left.equalTo(self.watermarkLabel).offset(self.watermarkLabel.frame.size.width);
  42. // make.width.equalTo(@20);
  43. // make.height.equalTo(@20);
  44. // }];
  45. _rotationBtn.frame = CGRectMake(self.bounds.size.width / 2 + _watermarkLabel.frame.size.width / 2 - 10, self.bounds.size.height / 2 + _watermarkLabel.frame.size.height / 2 - 10, 20, 20);
  46. _documentView.frame = self.bounds;
  47. _documentView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  48. }
  49. @end