PDFWatermarkImagePreview.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // CPDFImagePreview.m
  3. // PDFViewer
  4. //
  5. // Created by kdan on 2022/11/18.
  6. //
  7. #import "PDFWatermarkImagePreview.h"
  8. #import "Masonry.h"
  9. BOOL gImagePreviewIsFirstLayout = YES;
  10. @implementation PDFWatermarkImagePreview
  11. - (instancetype)initWithFrame:(CGRect)frame
  12. {
  13. if (self = [super initWithFrame:frame]) {
  14. _rotationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  15. [self.documentImageView addSubview:self.preImageView];
  16. [self.preImageView addSubview:_rotationBtn];
  17. }
  18. return self;
  19. }
  20. #pragma mark - Layout
  21. - (void)layoutSubviews {
  22. [super layoutSubviews];
  23. self.preImageView.layer.borderColor = UIColor.blueColor.CGColor;
  24. self.preImageView.layer.borderWidth = 1;
  25. [self.preImageView sizeToFit];
  26. self.preImageView.contentMode = UIViewContentModeScaleAspectFit;
  27. CGRect frame = self.preImageView.frame;
  28. frame.origin = CGPointMake(self.documentImageView.bounds.size.width / 2 - self.preImageView.frame.size.width / 2, self.documentImageView.bounds.size.height / 2 - self.preImageView.frame.size.height / 2);
  29. _watermarkFrame = frame;
  30. self.preImageView.frame = _watermarkFrame;
  31. [_rotationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.top.equalTo(self.preImageView.mas_bottom).offset(-10);
  33. make.width.equalTo(@20);
  34. make.height.equalTo(@20);
  35. make.left.equalTo(self.preImageView.mas_right).offset(-10);
  36. }];
  37. _rotationBtn.layer.cornerRadius = 10;
  38. _rotationBtn.layer.masksToBounds = YES;
  39. _rotationBtn.layer.borderColor = UIColor.blueColor.CGColor;
  40. [_rotationBtn setBackgroundImage:[UIImage imageNamed:@"btn_selected"] forState:UIControlStateNormal];
  41. }
  42. @end