CPDFBackgroundPreview.m 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // CPDFBackgroundPreview.m
  3. // PDFViewer
  4. //
  5. // Created by kdanmobile_2 on 2023/1/2.
  6. //
  7. #import "CPDFBackgroundPreview.h"
  8. #import "Masonry.h"
  9. @implementation CPDFBackgroundPreview
  10. - (instancetype)initWithFrame:(CGRect)frame {
  11. self = [super initWithFrame:frame];
  12. if (self) {
  13. _documentView = [[UIImageView alloc] init];
  14. [self addSubview:_documentView];
  15. _imageView = [[UIImageView alloc] init];
  16. [self addSubview:_imageView];
  17. self.backgroundColor = [UIColor systemGray5Color];
  18. }
  19. return self;
  20. }
  21. - (void)drawRect:(CGRect)rect {
  22. [super drawRect:rect];
  23. _imageView.layer.borderColor = UIColor.blueColor.CGColor;
  24. _imageView.layer.borderWidth = 1;
  25. [_imageView sizeToFit];
  26. _imageView.contentMode = UIViewContentModeScaleAspectFit;
  27. CGRect frame = _imageView.frame;
  28. frame.origin = CGPointMake(_documentView.bounds.size.width / 2 - _imageView.frame.size.width / 2, _documentView.bounds.size.height / 2 - _imageView.frame.size.height / 2);
  29. _imageView.frame = frame;
  30. }
  31. @end