// // CPDFBackgroundPreview.m // PDFViewer // // Created by kdanmobile_2 on 2023/1/2. // #import "CPDFBackgroundPreview.h" #import "Masonry.h" @implementation CPDFBackgroundPreview - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { _documentView = [[UIImageView alloc] init]; [self addSubview:_documentView]; _imageView = [[UIImageView alloc] init]; [self addSubview:_imageView]; self.backgroundColor = [UIColor systemGray5Color]; } return self; } - (void)drawRect:(CGRect)rect { [super drawRect:rect]; _imageView.layer.borderColor = UIColor.blueColor.CGColor; _imageView.layer.borderWidth = 1; [_imageView sizeToFit]; _imageView.contentMode = UIViewContentModeScaleAspectFit; CGRect frame = _imageView.frame; frame.origin = CGPointMake(_documentView.bounds.size.width / 2 - _imageView.frame.size.width / 2, _documentView.bounds.size.height / 2 - _imageView.frame.size.height / 2); _imageView.frame = frame; } @end