12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- //
- // CPDFDrawBackgroundView.m
- // PDFViewer
- //
- // Created by kdanmobile_2 on 2023/1/3.
- //
- #import "PDFDrawBackgroundView.h"
- @implementation PDFDrawBackgroundView
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
-
- if (self) {
- self.backgroundColor = [UIColor whiteColor];
- }
-
- return self;
- }
- - (void)drawRect:(CGRect)rect {
- [super drawRect:rect];
-
- CGContextRef context = UIGraphicsGetCurrentContext();
-
- [self showDraw:context];
- }
- - (void)showDraw:(CGContextRef)context {
- CGContextSetFillColorWithColor(context, self.dataModel.backgroundColor.CGColor);
-
- CGContextSetAlpha(context, self.dataModel.backgroundOpacity);
-
- CGFloat ctm = (self.dataModel.backgroundRotation * M_PI) / 180;
- CGFloat centerWidth = self.bounds.size.width / 2;
- CGFloat centerHeigth = self.bounds.size.height / 2;
-
- CGContextTranslateCTM(context, self.dataModel.horizontalSpacing, - self.dataModel.verticalSpacing);
- CGContextTranslateCTM(context, centerWidth, centerHeigth);
- CGContextRotateCTM(context, ctm);
-
- CGContextScaleCTM(context, self.dataModel.backgroudScale, self.dataModel.backgroudScale);
- if (_dataModel.image) {
- [_dataModel.image drawInRect:CGRectMake(- centerWidth, - centerHeigth, self.frame.size.width,self.frame.size.height) blendMode:kCGBlendModeNormal alpha:self.dataModel.backgroundOpacity];
- } else {
- CGContextFillRect(context, CGRectMake( - centerWidth, - centerHeigth, self.bounds.size.width, self.bounds.size.height));
- }
-
- CGContextRotateCTM(context, -ctm);
- CGContextTranslateCTM(context, - centerWidth, - centerHeigth);
- }
- @end
|