CPDFTextPreview.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. BOOL gTextPreviewIsFirstLayout = YES;
  10. @implementation CPDFTextPreview
  11. - (instancetype)initWithFrame:(CGRect)frame
  12. {
  13. if (self = [super initWithFrame:frame]) {
  14. _watermarkLabel = [[UILabel alloc] init];
  15. _rotationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  16. _documentView = [[UIImageView alloc] init];
  17. [self addSubview:_documentView];
  18. [_documentView addSubview:_watermarkLabel];
  19. [_watermarkLabel addSubview:_rotationBtn];
  20. }
  21. return self;
  22. }
  23. - (void)layoutSubviews {
  24. [super layoutSubviews];
  25. _watermarkLabel.layer.borderWidth = 1;
  26. _watermarkLabel.layer.borderColor = UIColor.blueColor.CGColor;
  27. [_watermarkLabel sizeToFit];
  28. if (gTextPreviewIsFirstLayout) {
  29. CGRect frame = _watermarkLabel.frame;
  30. frame.origin = CGPointMake(_documentView.bounds.size.width / 2 - _watermarkLabel.frame.size.width / 2, _documentView.bounds.size.height / 2 - _watermarkLabel.frame.size.height / 2);
  31. _watermarkLabel.frame = frame;
  32. gTextPreviewIsFirstLayout = NO;
  33. }
  34. _rotationBtn.layer.cornerRadius = 10;
  35. _rotationBtn.layer.masksToBounds = YES;
  36. _rotationBtn.layer.borderColor = UIColor.blueColor.CGColor;
  37. [_rotationBtn setBackgroundImage:[UIImage imageNamed:@"btn_selected"] forState:UIControlStateNormal];
  38. [_rotationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.top.equalTo(_watermarkLabel.mas_bottom).offset(-10);
  40. make.width.equalTo(@20);
  41. make.height.equalTo(@20);
  42. make.left.equalTo(_watermarkLabel.mas_right).offset(-10);
  43. }];
  44. }
  45. @end