用CAShapeLayer与UIBezierPath来画。 CGRect frame = _scanRectView.frame; CGFloat detaSpace = 3.f; frame.origin.x += detaSpace; frame.origin.y += detaSpace; frame.size.height -= detaSpace * 2.0; frame.size.width -= detaSpace * 2.0; UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:_scanBgView.bounds cornerRadius:0]; UIBezierPath *rectPath = [UIBezierPath bezierPathWithRect:frame]; [path appendPath:rectPath]; [path setUsesEvenOddFillRule:YES]; CAShapeLayer *fillLayer = [CAShapeLayer layer]; fillLayer.path = path.CGPath; fillLayer.fillRule = kCAFillRuleEvenOdd; fillLayer.fillColor = [UIColor colorWithWhite:0.0 alpha:0.8].CGColor; fillLayer.opacity = 0.5; [_scanBgView.layer addSublayer:fillLayer]; 这是我用到的画方形的代码。
用CAShapeLayer与UIBezierPath来画。
这是我用到的画方形的代码。