单军华
2018-07-11 7b02207537d35bfa1714bf8beafc921f717d100a
screendisplay/Pods/HMQRCodeScanner/HMQRCodeScanner/QRCode/HMScannerMaskView.m
New file
@@ -0,0 +1,42 @@
//
//  HMScannerMaskView.m
//  HMQRCodeScanner
//
//  Created by 刘凡 on 16/1/3.
//  Copyright © 2016年 itheima. All rights reserved.
//
#import "HMScannerMaskView.h"
@implementation HMScannerMaskView
+ (instancetype)maskViewWithFrame:(CGRect)frame cropRect:(CGRect)cropRect {
    HMScannerMaskView *maskView = [[self alloc] initWithFrame:frame];
    maskView.backgroundColor = [UIColor clearColor];
    maskView.cropRect = cropRect;
    return maskView;
}
- (void)setCropRect:(CGRect)cropRect {
    _cropRect = cropRect;
    [self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [[UIColor colorWithWhite:0.0 alpha:0.4] setFill];
    CGContextFillRect(ctx, rect);
    CGContextClearRect(ctx, self.cropRect);
    [[UIColor colorWithWhite:0.95 alpha:1.0] setStroke];
    CGContextStrokeRectWithWidth(ctx, CGRectInset(_cropRect, 1, 1), 1);
}
@end